AppleScript: automation for the rest of us

So in the course of publishing these sections of Flatland, I have found I needed to reformat and clean them up (sometimes for odd line breaks, other times for artifacts that textile would misinterpret). It boiled down to a few common operations, and after reading Gruber’s writeup on how AppleScript-ability makes for a world-beating OS X app, it struck me that I have rarely used Applescript in OS X. I found myself playing with some the scripts that come with ecto (Thanks, Adriaan.) and realized it was worth another look.

So this time, when I copied from ecto to TextWrangler to use the search and replace options there, I turned on the Recording option in the Scripts menu and let it log my movements. The result?

tell application “TextWrangler”

activate
replace


using “•” searching in text 1 of text document 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}

replace

using ” ” searching in text 1 of text document 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}

replace “•” using


searching in text 1 of text document 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}

replace “–” using ” — ” searching in text 1 of text document 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
replace ” ” using ” ” searching in text 1 of text document 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}

end tell

And it works just fine. Faster than keystrokes, I can attest to that. I couldn’t have written this, based on what I know now, but I can now pick this apart and add or adjust some of the steps, with this as a template.

NB: if you try this — recording some steps you already perform — the results are stored in ~/Library/Application Support/${Application}/Scripts. You can then open your handiwork in the Script Editor (accessible through the Scripts menu) and see what you ended up with.

Now playing: Thanks For The Pepperonni by George Harrison from the album “All Things Must Pass [Disc 2]” | Get it (1)

Leave a Reply

Your email address will not be published. Required fields are marked *