Created
August 25, 2010 20:34
-
-
Save dsanson/550236 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 | \ | |
ruby -ne '@found=true if $_ =~ /<body>/; next unless @found; exit if $_ =~ /<\/body>/; puts $_;' | \ | |
grep -v "</body>" | \ | |
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 script converts RTF text on the clipboard to HTML, and then pastes the HTML into the currently active application. For the "currently active application" to make much sense, it needs to be run using Fastscripts or a Quicksilver Trigger, or as a Service via Automator.
The pasting part doesn't work with Firefox, but the conversion part still does.