Better living through automation, pt. 1
Anything that's tedious is repeatable; anything that's repeatable should be done by a computer.-Robert Muller
I spend a lot of time working on my computer every day. Many of the tasks that I need to perform on a computer can be incredibly tedious. Copying and pasting text from a website into a spreadsheet. Renaming a bunch of files and moving them to a new location. Zipping a bunch of directories and uploading them to a website one by one. From an early age, I was always frustrated at these kinds of tasks. It's a tragic waste that we have commodity PC's capable of performing billions of calculations a second, but are still left doing the same tedious crap that we were doing 10 years ago.
Clearly, there's no lack of machine 'brainpower.' What most people lack is the knowledge required to effectively leverage their personal computers to automatically perform tedious tasks for them. I have successfully automated all of the tedious tasks I mentioned above in my own workflow, and many more.
My mission with this series of articles is to provide a high-level overview of the most effective technologies for automation that I have used, and share some pointers that have been key to my success. There are already many great tutorials that go in depth into how to use these particular technologies. I will try to provide links where appropriate, but a quick Google search is usually sufficient to turn up lots of great resources on any particular technology or program. If a technology I describe sounds useful and interesting to you, I encourage you to go try it! Monkey around with it, Google when you get stuck, and try to solve at least a small part of a real problem you are having that could use some automation. That's how I learned everything that I know now.
If there's anything you'd like me to explain in more depth, please leave a comment and let me know what it is. I will try to help, or at least point you to where you can find more information.
I'd like to talk a little bit about Mac OS X. At this time of writing, Mac OS X is my favorite desktop operating system. Here's why:
- By default, everything works pretty much how I want it to.
- Because Mac OS X is built on top of Unix, there's a ton of flexibility built in. At any time, I can drop down to the command line to accomplish what I need to.
Granted, Mac OS X is nowhere near as configurable and customizable as a modern desktop GNU/Linux system. However, even with the advent of fairly easy-to-use Linux distributions like Ubuntu, I think the barrier to entry might still be a little bit too high for the average user. We'll get there eventually.
Automator
From an automation standpoint, Mac OS X is at the top of its game. Included with the OS is a really slick application called Automator. Automator allows you to "snap together" instructions from a library of parts to create a workflow describing what you want the computer to do. Essentially, it allows you to create your own scripts without writing a line of code. You can even save them as application bundles and send them to other people. This is a great place for someone who wants to dive in to the world of automation without any prior experience. The ability to install custom "actions" created by others, and write your own actions in AppleScript, allows room to expand the capabilities of Automator. Some tasks I have used Automator for include:
- Re-sizing, renaming, or moving batches of photos (I recommend the Proper Cropper action for cropping instead of Apple's default.)
- Performing a series of repetitive keystrokes in an application to load files in by the batch (this made use of a custom AppleScript module to simulate key presses)
One of the reasons I don't like Automator and don't use it more often is the fact that, as far as I can tell, you have to write your custom code in AppleScript. (Edit: I recently discovered that Python and Ruby are available as alternatives, see my comment below.) AppleScript tries to appear like natural language, but it's just a trick. It's just as rigid as any other programming language, but the syntax is just kind of weird and occasionally ambiguous. You are also limited to whatever actions ship with Automator, or whatever ones you can find online or write yourself using AppleScript. In the end, I found Automator a great way to interface specifically with Mac OS X GUI applications and do certain common tasks, but that I had to turn elsewhere for real ultimate power.
Up next:
- The Shell and Coreutils
- Shell Scripting: Becoming a Wizard
- Curl: Internet Magic Sauce
Stay tuned!