Last active
January 18, 2020 08:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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