2006/04/05

MarsEdit applescript: the way it should be

Having temporary luck with MarsEdit is prompting a couple of quick posts detailing some Applescripts I wrote to improve my workflow in the app. I like to write in Markdown, but Blogger requires HTML (as far as I know; haven’t spent much time on the whole thing).

So, easy to fix with Applescript. Just write something that’ll “Markdown” the text in my MarsEdit window (including SmartyPants) and then send the post through. Here we go:

tell application "MarsEdit"
    set plaintext to the body of the front post window
end tell

tell application "Finder"
    set homepath to POSIX path of (home as alias)
end tell

set markdown to "/usr/bin/perl " & homepath & "bin/Markdown "
set smartypants to "/usr/bin/perl " & homepath & "bin/SmartyPants -2 "
set webtext to do shell script "echo " & quoted form of plaintext & " | " & markdown & " | " & smartypants

tell application "MarsEdit"
    set the current text of the front post window to webtext
    tell the front post window to send post to weblog
end tell

I know it’s not the best Applescript ever, but it makes life for me much easier.