Blogging about our lives online.


Automate The Itch - Part 1


Small, single-purpose utility applications have a long lineage in computing history. They are the cornerstone of the UNIX philosophy, and are rampant on mobile platforms. They are the small building blocks in a larger task. These are apps that scratch an itch. They do things that could be done in another way, but with less time and effort.

Every Mac comes with a tool for building your own utility apps quickly and painlessly: Automator. These apps don't need to clutter your dock, but can sit in the contextual menu (right-click) whenever you need them. This series will show you how to build a few useful apps, and hopefully give you the tools to dream up your own.

The first part will deal with files and folders, then I'll dive into network tasks, and finally text. I may also throw in a bonus section on porting some command-line wizardry to Automator.

Batch Renamer

One of the most common, time consuming tasks is emailing files. You may want to rename them, compress them or convert them somehow. Automator can deal with almost any of these tasks. Say you have 1000 files named [DSC1020.jpg-DSC2020.jpg], and want them to be called [Vacation0001.jpg - Vacation1001.jpg]. Here's how Automator can help.

  1. Open Automator and make a new "Service"
  2. Set the service to receive files or folders in any application.
  3. Add a "Rename Finder Items" action. (Don't make new copies of the files)
  4. Change "Add Date & Time" to "Make Sequential".
  5. In the actions "Options" pane, click "Show this action when workflow runs", so you can tweak the settings each time you run it.

Save it and it will show up whenever you right click any files or folders.

Resize Images

If you email photos a lot, your workflow may also include copying them and resizing them. Here's how that might look:

  1. Create a "Service" that receives "image files", or just continue on from the previous workflow.
  2. Add a "Copy Finder Items" action. Set it to copy to the Desktop, your Dropbox or wherever you want the new files.
  3. Add a "Scale Images" action and set the scaling. 600-pixels is probably good for general usage. If you want to adjust this each time it's run, check the box "Options > Show this action when run"
    4a. Optionally: add a "Reveal Finder Items" action to show you the files in Finder when it's complete. This one throws an error for me, even though it does the job perfectly, so it's up to you…
    4b. Or: add a "New Mail Message" action to automatically add those photos to a new message in Mail. If you're feeling lucky, you can also add a "Send Outgoing Messages" action to automatically send the prepared email.

Other Handy File Actions

  • Use "Sort Finder Items" prior to a sequential rename, to organize them by date, kind or size.
  • Include "Label Finder Items" or "Set Spotlight Comments" to organize the files you run through a particular workflow.
  • "Create Archive" is useful if you want to zip the files before sending.
  • "New Alias" is a great one-action service that just takes the selected files or folders and makes a shortcut on the Desktop.
  • Use "Choose From List" whenever you need to confirm an action. You then have the option to "Select None" or pick and choose items before the workflow continues.

Bonus Points - Email Screen Recording

Here's a much more esoteric, but potentially very useful workflow. This one captures a screen recording, and emails it to someone.

  1. Make a new "Application".
  2. Add a "New Screen Capture" action.
  3. Add a "Start Capture" action and check the box "Wait for capture to complete"
  4. Add a "Ask For Finder Items" action, and set it to start at "Movies". This is where screen recordings are saved by default.
  5. Add a "New Mail Message" action like before. The selected movie will get added to the body of the mail message.

This starts the recording right away, if you haven't used screen recording in QuickTime you probably want to run it once manually to set up your levels. Instant tutorials!


Hashtag Search


As a sideline to one of my bigger projects, I decided to build a little webapp that would search Twitter for a hashtag. Fairly basic, but it's got a few interesting little features:

  • Name & profile pics link to user's profile
  • Inline URL's are converted to links
  • 'More' button loads more tweets via AJAX

Source on Github

Online Version


Automator Services


I keep discovering new uses for Automator.

I'm not sure when the "Services" option became available, but it's worth checking out. I had previously wrote a text-to-markdown action, which converted the clipboard contents from markdown to HTML. This was convenient, but it involved copying, running the app and then pasting. The script did this:

pbpaste | | pbcopy

With services this becomes much simpler. It's now in the contextual(right-click) menu for any application that deals with text, and I also set up the keyboard shortcut CMD-ALT-SHIFT-M. It replaces the selected markdown text with the HTML. The action is even simpler; just a single command:


If you've installed the markdown script somewhere else, you'll have to set the appropriate path. And here's a screenshot of how the input is configured.

Search and Replace

Almost any shell command can be wired into OSX this way. If the command needs special arguments for each run, just check the box: Options > Show this action when the workflow runs. I did this for Sed search and replace action. Here's the workflow script:

sed s/old/new/g

On each run you want to change old and new with what you're searching and replacing, but it doesn't have to end there. You can change the command on the fly to anything that deals with text transformation. sed /^$/d deletes any empty lines. grep andyvanee filters out any lines not containing 'andyvanee'.

View Command Output

For text commands where you don't want to replace the text, just see the results of some command, uncheck the 'Replaces Selected Text' box and add a "Choose From List" action, or maybe "New TextEdit Document" to view the results. For good measure, add a "Copy to Clipboard" action at the end, just in case you want to do something with the output of the command.

This is probably more useful for grep type commands, so I saved this one as "Grep Text" and the previous as "Sed Text", although either can be used for a wide range of commands.


Democamp 13


I went to my first Democamp this evening. I thought I'd share the experience while it's still fresh in my mind.

First off, I wasn't too sure what to expect, but it was fairly close to what I thought. The community is pretty tight, and there is a good energy. There was only 5 demos, and a couple were somewhat underwhelming, but I'll start with the good: presented their new app for selling stuff on fb/twitter and sharing the profits with the friends who helped you get the word out. Seems like a great idea, and it seems like they've thought it through quite well.

A guy (I forget his name!) from 3Di who works with their pureLIGHT lighting engine presented his concept game that was pretty cool. It was based on the idea of mapping the 3D engine onto curved space... Kind of hard to describe, and unfortunately his demo only covered the basic "training" level, which wasn't very curved at all, but I could definitely see the potential of a game that ran with that idea. The graphics and lighting were very top-notch for indie developer.

There was guys from deckle there. Solid looking application, but I had this creepy feeling when they demoed the feature of printing bank quality cheques. I suppose I'm just not all that starstruck with the wonders of print media.

And the rest don't really deserve links, in my humble opinion.

Afterwards, we headed to the pub and I got a chance to meet some cool people in the Edmonton developer community. Good stuff!


Rapid Game Prototyping in Quartz Composer


I am a Quartz Composer junky. I love tinkering with ideas and hacking together logic gates within this kind of visual programming environment.

I think this it's the best way to teach core CS techniques that are often obscured in text-based code. Things like logic gates, the value of modularity, and application structure start to really make sense when you lay them out visually. It's like a UML diagram that functions and evaluates in real-time.

As an example, I will use a game-idea I had, and how I quickly mocked it up in Quartz Composer. It's called "Stellar Debris", and the point of the prototype is to demonstrate vertical parallax motion in a 2D game (like the background scrolling in Canabalt).

The storyline is that your character is a flying robot(spaceship?) that takes off from the surface and must make it through the layer of orbiting debris in a post-apocalyptic earth. The controls are very basic, click to takeoff, mouse back and forth to move and click to shoot.

Here's the start screen. The graphics are very rudimentary (prototype remember!).

Once you click, the character takes off and you can control his motion and fire bullets.

You'll notice the foreground has scrolled off screen already and there are blocks to shoot. The background scrolls much slower, and the sky doesn't scroll at all. It also gets darker as you ascend into the atmosphere.

Game Logic

I don't think I would want to build an entire game in Quartz Composer. But having a mockup like this is great for prototyping because most of the game logic is there in a clear modular structure, which makes it a great starting point for porting it to your programming language of choice. Here's a look at the patches involved in making this "game" happen.

Rather than coding blindly, many of the logic bits required for gameplay are already in place. Things like "the bullet needs to know the character's position at the time of firing" or "each 2D layer needs to know the absolute position and multiply it by some factor" or even "the clouds look good enough as a blurred semi-opaque sprite".