Such a nice surprise to wake up and find an interview with Ben Waldie about Automator. Electron for electron, the 5By5 network content beats any TV network out there for pure enlightenment and entertainment.
Automator
2
Jan 12
Markdown Services [Link]
Just to prove how late-to-the-party I am, here’s Brett’s Markdown Services from September
2
Jan 12
Automator App Backup [Link]
Nice tip from Macworld to automatically backup versions of applications. I’m not sure I agree with the reasoning for doing it though. If a developer removes or changes a feature that I’m not happy with, I’m more likely to find a different app than to constantly skip updates or hassle with reinstalling an old version. It’s way too easy to choose “Download All Free Updates” than it is to selectively update individual apps.
Philosophy aside, it’s a nice Automator workflow.
24
Dec 11
What’s So Fun About Fake?
I wrote about the Mac application “Fake”[1] awhile ago. From my very first use, I thought it was an incredibly clever tool. Fake is like a super-charged automator for Webkit. It makes automating interactions with webpages easy and simple. But why would I want to use Fake instead of Automator or curl or even a Python script? Here’s an example that I just started using.
If I want to add an affiliate link for a Mac or iOS app, I need to visit the Apple Link Maker page with my affiliate id as a get-parameter in the link. Then I need to choose iOS or Mac apps and type in the application name. I hit search and get back a list of apps. If I typed the name correctly, then the app I want will be on the top of the list.
I’m not done yet. I want the link, so I click the “App Link” to get a pop-over. I then select the link text and copy it. It’s kind of tedious and therefore, I haven’t used them much. What’s worse, all of the content only exists after the JavaScript has executed and added the content to the page. I can’t just submit a form and get a new page, I have to click the Submit button to generate the new document elements. That’s where most web scraping breaks.
This is a common problem with automating web-interactions. Automator, curl or python’s urllib will not have access to the content I want. That’s because developers are expecting a javascript engine to insert content into the DOM. Without a JS engine, the urllib2, Scrapy or BeautifulSoup functions are not useful.[2] That’s where something like Fake comes in handy.
Hello Fake
With Fake, I can automate the entire process. I build a Fake workflow much like I build an Automator workflow. Drag and drop actions and set variables. Fake has auto-discovery for form fields too. Just ctrl-drag from the action to the location on the page to auto-discover the element id. Fake will automatically determine the proper tag hierarchy to find it in the future.
Fake can also press buttons on the page. Now I’m getting somewhere. It can even extract the content I need from the JavaScript pop-over.
Here’s the workflow:
Macro Time
But how can I automate this process? Well, I kind of like Keyboard Maestro for this kind of stuff. Luckily, Fake has good AppleScript support. In my macro, KM pops up a form where I choose an app type[3] and type an app name to query. Next, an AppleScript is executed to launch the Fake workflow.
activate
open "Macintosh HD 2:Dropbox:Development:Fake Workflows:getAppLink.fakeworkflow"
delay 1
run workflow
wait until done
close front document
quit
end tell
Fake can also run AppleScript so it can also get variables from Keyboard Maestro. Here’s the code from the first Fake action that grabs the input from the form:
tell application "Keyboard Maestro Engine"
set kmVarAppName to (process tokens "%Variable%AppName%")
set kmVarAppType to (process tokens "%Variable%AppType%")
end tell
tell application "Fake"
set variable with name "appName" to kmVarAppName
set variable with name "appType" to kmVarAppType
end tell
Now fake has all of the information needed to load the page, populate the drop downs, click submit and then load the JavaScript pop-over. Finally, it copies the affiliate link to the clipboard for me.
The final workflow goes something like this:
- cmd-opt-M to open my Markdown palette of macros
- Type C to choose the macro for appstore affiliate links
- Fill out the popup form and click ok
- wait for the alert that the macro is complete
- paste the affiliate link
Nice. I’m starting to play with Fake as more than just a way to probe web pages. It has some great potential. I haven’t even touched the more powerful actions that allow custom JS to be run against a page.
I would like to see more options to export a workflow to a stand-alone applet or script. Or perhaps a separate headless engine that could run independent of the application (like Keyboard Maestro). I’d also like integration with 1Password for autofill of passwords. I have a couple other ideas for automation that would require hard-coding login credentials and I’m not a fan of that.
- Affiliate Link ↩
- There are things like Selenium that provide a JS engine to Python but I find it to be overly difficult and time consuming to use. I’m also not good at Python. So there’s that. ↩
- I find it interesting that the form value submitted for iOS apps is “software” and the form value for Mac apps is “macSoftware” ↩
17
Oct 11
Remote Macro Execution
Keyboard Maestro macros can be executed several different ways. There’s the common hot-key trigger and text snippet trigger. These are great but sometimes I need to run a macro when I’m not sitting in front of my computer. That’s where the KM Webserver trigger and Keyboard Maestro iOS apps come in handy.

Webserver
This a somewhat understated feature of Keyboard Maestro. I can configure the application to expose a webserver running on a specific port. Selecting a Webserver trigger will expose the macro through a web page to anyone on a browser via my local network. That’s pretty nice, but I also expose my server through the internet. That means with the proper port forwarding I can make macros available over the internet too.
I’m smarter than I look, so I don’t just allow anyone to run a macro remotely. On my server, Keyboard Maestro requires authentication through the web page to run a macro. Additionally, most of the macros are relatively benign.
One, more sinister, macro I built could come in handy if my Mac every went missing. As long as the account is online, I could trigger a macro to take a screenshot as well as snap an iSight photo. Both are added to my Dropbox account. It’s also easy enough to have it send upload a text file with IP and location information through Dropbox. I’m sure I could think of a number of other mean spirited things to do too, but honestly, this was more for proof of concept. I don’t anticipate ever needing to use it.
To build this macro, first create an Automator workflow for grabbing an iSight photo and saving it with a date and time stamp to the appropriate Dropbox folder.
Next, create a short macro that activates the screensaver and then turns off the volume (so they do not hear the audible countdown) . Finally, the macro executes the Automator workflow to grab the screenshot.
All of these activities happen when triggered remotely by the KM webserver.
iOS App
Stairways Software makes a barebones iOS companion app. It’s pretty useless without the Mac application. However, it’s a tremendous tool when it is combined with the Mac application.
The iOS app performs two simple functions, provide the full list of macros available on your Mac (support for multiple machines too) and the ability to execute any macro displayed.
Limitations
Before you get too excited, the KM iOS app doesn’t suddenly give you a bunch of text conversion macros or quick access to the pasteboard on iOS. It is more of a remote trigger for the macro as it would run on your Mac. So if your macro is set to paste a bunch of text into the front most window, that action will happen on your Mac, not your iPhone.
Usage
While KM on iOS will not replace TextExpander Touch or Pastebot it does provide for some very interesting options. You know those old-timey apps that could only sync from your iPhone or iPad to your Mac over wifi. It sure is a pain when I try to sync those apps and realize they are not currently running on my Mac (I’m looking at you Bento). KM to the rescue.
I configured a macro to start the application on my Mac and sibling macro to shutdown the application. If I try to sync Bento on my iPad and realize that it’s not running on my Mac, I can just fire-up KM on iOS and run the macro to launch Bento. Voilà, Bento is now ready to sync.
This trick is also handy for those times when you sit down to stream a movie to the AppleTV and realize iTunes isn’t running. And Now that iTunes can sync over the air with an iPad or iPhone, it’s more important than ever to remotely start iTunes.
30
Aug 11
Don't Forget About Automator
It’s a mature tool now, that has a huge amount of power. I often forget about how easy Automator is to use and set out writing Python or AppleScript when Automator provides a solution in a few clicks. Many times it’s a one-off solution that I don’t even bother to save.
Here’s an example I used tonight to convert a folder of .md and .mmd files to plain text files and also set their default application to Byword (Thanks for the recommendation Brett).

17
Aug 11
More Fun With Markdown Text Services
I couldn’t resist. Here are some more generic solutions for text processing via the Services Menu. Create an Automator Services project that accepts text and replaces the selection with the result as shown. Add a “Run AppleScript” step to the workflow.
Here’s the AppleScript to convert a selection of text to a bulleted Markdown list:
set inputString to input as string
set newList to {}
set myString to paragraphs of inputString
repeat with myItem in myString
set NewItem to "- " & myItem
set end of newList to NewItem
end repeat
set AppleScript's text item delimiters to "
"
set combinedList to newList as text
return combinedList
end run
Once the service is installed, you can select a series of text lines like this:
item 2
item 3
and turn it into a bulleted Markdown list like this:
- item 2
- item 3
Here’s the AppleScript to generate a numbered list
set currentCount to 1
set inputString to input as string
set newList to {}
set myString to paragraphs of inputString
repeat with myItem in myString
set NewItem to currentCount & ". " & myItem as string
set end of newList to NewItem
set currentCount to currentCount + 1
end repeat
set AppleScript's text item delimiters to "
"
set combinedList to newList as text
return combinedList
end run
And finally, here’s one that takes a series of URL’s and converts them into a set of link references. This is useful if you gather a bunch of reference links before writing and you want to convert them all into a series of references. The reference titles are automatically incremented by the script. I added one additional step to this workflow to extract the URL’s from the text. 
set currentCount to 1
set newList to {}
repeat with myUrl in input
set NewItem to "[Link_" & currentCount & "]: " & myUrl as string
set end of newList to NewItem
set currentCount to currentCount + 1
end repeat
set AppleScript's text item delimiters to "
"
set combinedList to newList as text
return combinedList
end run
This will take a series of links like this:
www.google.com
www.omnigroup.com
and convert it into a list of link references like this:
[link_2]: www.google.com
[link_3]: www.omnigroup.com
17
Aug 11
Create a Text Service That Uses BBEdit
If you are a proud user of BBEdit, don’t forget that it can help with text anywhere in the OS through the services menu.
Using Automator, you can build new services that receive selected text and replace it with some processed text. Here’s an example for use with Markdown enthusiasts. I hate when I am working in TextEdit or NVAlt and I forget to prepend a list with bullets. This service fixes that.

There are a bunch of services available through BBEdit. If it is not already running, BBEdit will be launched to perform the text modification
2
Jul 11
Veritrope AppleScript Archives [link]
I stumbled across Veritrope while researching some OmniFocus AppleScript-ing. It has a number of generally useful scripts. It’s chock full of examples, tips and resources of all kinds.
20
Jun 11
Updated Handbrake CLI Settings and Automated DVD Encoding
Back in January I posted about a workflow for automatic processing of DVD’s. This is really handy if you are processing a bunch of home movies from DVD to an AppleTV friendly format (or any other format). I’ve updated my settings (and corrected a typo) from that post. I like the look of strict anamorphic video better on one of my videos so it was easy to simply modify the Automator workflow. I was also having some issues with the Hazel portion of the workflow moving the DVD image before it was done encoding. I modified the new Hazel script as follows:
1. RipIt creates a dvdmedia file of the disk in a folder called “Encode”
2. Hazel monitors the “Encode” folder for files of type “dvdmedia” and color label not set to green. If it identifies a file it runs the following sequence:

3. The modified automator workflow now looks like this:

Importantly, the file is now moved by the workflow and not by Hazel. This way, the file is only moved after the workflow ends. Interestingly, this was not an issue until I upgraded to an SSD. It may be coincidental but I wouldn’t be surprised if this problem was an artifact of the incredible performance of SSD resulting in the file move taking too little time to allow Handbrake to start the second round of the 2-pass encoding.
4. Finally, Hazel Monitors the disk image archive for any “dvdmedia” file types and renamed the file to a bit more friendly format:

This is one of my favorite tweaks. It saves a ton of time that is easily relegated to a machine. The work starts with popping a DVD into my iMac and ends when the processed file is saved and the disk image archived. Pretty darn close to magical.
23
Jan 11
Auto-Rip DVD's with Hazel
Hazel by Noodlesoft is a really fantastic little helper application. It’s really what folder actions should have been. It’s the rare example of how Apple missed the target and an independent developer really nailed it.
I’m going to skip the Hazel tutorial and get right to the main show. I wanted a system for ripping DVD’s of all kinds. Typically this is a manual process where I rip a disk image to my harddrive and then extract the video at the appropriate resolution. I like to save the disk image externally, in case I ever need to re-extract the movie at a different resolution. This entire process was relatively manual until I developed this system that relies on four applications (2 free and 2 paid):
- Hazel
- RipIt
- Automator
- Handbrake CLI
Here’s the setup:
I use RipIt to extract the disk image. It is simple and has never failed me. Set RipIt to be the default application for when DVD’s are inserted. You will also need a couple of specific settings in RipIt. For the Hazel workflow to process the file properly, the file needs to be ripped to specific folder. I’m also using the .dvdmedia extension so Hazel recognizes the completed rip.

Once the rip is done, Hazel gets to work with the file. It looks for the .dvdmedia files that DO NOT have a color label of green (more on this later). It then posts a Growl notification to let me know that the DVD conversion is starting. After the Growl notification, an Automator Workflow is run.

The Automator workflow is where all of the magic happens. It’s based on the automator actions you can find here on the Handbrake forum. It is essentially using the Handbrake CLI interface to extract the video from the DVD image file with my preffered settings. I prefer to use a custom encode string rather than rely on one of the Handbrake presets. I like constant quality video with several audio encodes. The Automator actions are pretty self explanatory. But you can read through the Handbrake CLI reference to set your own encode settings.

I have the workflow extract the video to a new folder so that I can tweak the meta data later. When the video encoding is complete, Hazel then sets the video label to green so that I know the file has already been processed. The file is then moved to a master directory where I store all of my dvd images.
That’s pretty much it. I followup later with MetaX for setting all of the meta data. I could automate that process too, but I’m fairly particular about all of the meta data so I like to manually set all of the chapter markers and synopsis info.
29
Jul 07
One script to rule them all

I tend to listen to Podcasts (one of the best is MacBreak Weekly) while I work. But when my wife starts talking to me from the other room, I have to stop what I’m doing to navigate to iTunes just to click Pause. It finally reached a level of annoyance that made me fired up Script Editor and throw together a little script to do it for me. This is just about as simple an Apple Script as you can get:
tell application “iTunes”
playpause
end tell
Now, just save it as an application and bind it to some key you’re not using. I used one of the buttons on my Wacom Tablet. One key press and the podcast will either pause or play depending upon its current state.
It’s so great that Apple included a little hook for the Pause/Play function. This is yet another great feature of OSX. If something’s missing that you really want it to do, chances are that a short Apple Script or Automator Action can remedy the situation.
I think this little trick will hold me over until that new keyboard sees the light of day.
Technorati Tags: Apple, AppleScript, Mac, Programming, iTunes, Tip
12
Nov 06
Image sucking with Automator
Here’s a quick Automator script to pull all of the image links in the frontmost Safari window into iPhoto. I use this when I stumble across a web page with great photos I want to add to my gallery.
Notice that what this script does is download to the desktop and then import to iPhoto. After completion, it deletes the originals from the desktop. This way I am sure to get the full resolution images rather than the lower resolution web thumb nails
Technorati Tags: Apple, Automator, iPhoto, Mac, Productivity, Programming, Tip, Trick
23
Sep 06
Quick shot Automator
I use a lot of Applescript when I use my Mac. I’ve learned quite a bit about the language over the years. Needless to say that it makes me a little snobby about using Automator. For the most part, I hate automator because it is so limited. What it has is pretty much all you get to do. However, once in awhile I gain an added appreciation for its simplicity. Here is an Automator “script” that takes a screenshot and then places the screen shot in my blog photos library within iPhoto. I’m sure if I worked long enough I could have come up with an Applescript to do it, but Automator allowed me to do it in about 10 seconds of work. Here it is (and yes, I used this automator “script” to take the screenshot)
Technorati Tags: Apple, Mac, OSX, Programming, Automator, Software





