Skip to content

Instantly share code, notes, and snippets.

@jbarr21
Last active January 18, 2020 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarr21/c5ee2381a97f98b8246dd060b0d5a257 to your computer and use it in GitHub Desktop.
Save jbarr21/c5ee2381a97f98b8246dd060b0d5a257 to your computer and use it in GitHub Desktop.
Copies the contents of the general string pasteboard on Mac OSX over to HTML for easy pasting into Google Docs
// Utility to help with converting markdown on the clipboard into html on the
// clipboard for easy pasting of formatted text into a Google Doc in Chrome.
//
// Setup:
// - brew install pandoc
// - alias md2gd='pbpaste | pandoc -f markdown+smart -t html | pbcopy; swift pasteboardAsHtml.swift; echo "Copied to clipboard";'
//
// Usage:
// - <Copy some markdown text>
// - md2gd
// - <Paste the formatted text into a Google Doc in Chrome>
import Cocoa
let pb = NSPasteboard.general
if let string = pb.string(forType: NSPasteboard.PasteboardType.string) {
pb.declareTypes([NSPasteboard.PasteboardType.html], owner: nil)
pb.setString(string, forType: NSPasteboard.PasteboardType.html)
} else {
print("Could not read string data from pasteboard")
exit(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment