Created
August 25, 2010 21:03
-
-
Save dsanson/550291 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
# Convert RTF contents of clipboard to HTML | |
osascript -e 'the clipboard as «class RTF »' | \ | |
perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | \ | |
textutil -format rtf -convert html -stdin -stdout | \ | |
pandoc -f html -t markdown | \ | |
pbcopy | |
# Paste contents of the clipboard into the current application | |
osascript <<EOF | |
(* | |
First we need to get the name of the current application. Trick | |
borrowed from http://vanderbrew.com/blog/2010/02/15/get-current-application-with-applescript/ | |
*) | |
on GetCurrentApp() | |
tell application "System Events" | |
set _app to item 1 of (every process whose frontmost is true) | |
return name of _app | |
end tell | |
end GetCurrentApp | |
set _app to GetCurrentApp() | |
(* | |
Now we need to paste into the current app. I don't know any way to do this | |
aside from using GUI scripting (ugh). | |
*) | |
tell application _app to activate | |
tell application "System Events" | |
tell process _app | |
tell menu bar 1 | |
tell menu bar item "Edit" | |
tell menu "Edit" | |
click menu item "Paste" | |
end tell | |
end tell | |
end tell | |
end tell | |
end tell | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a script that converts RTF text on the clipboard to markdown, and then pastes that markdown into the currently active window. For reasons I don't understand, the pasting part doesn't work with Firefox. I run the script using a Quicksilver trigger. If you run it from the command line, it will attempt to paste the markdown into the terminal window, which is probably not what you want.