Skip to content

Instantly share code, notes, and snippets.

@dsanson
Created August 25, 2010 21:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dsanson/550291 to your computer and use it in GitHub Desktop.
Save dsanson/550291 to your computer and use it in GitHub Desktop.
#!/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
@dsanson
Copy link
Author

dsanson commented Aug 25, 2010

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment