Possibly to my peril, I decided I’d spend a little of the Christmas vacation (and the resulting absence of lectures and coursework) to learn AppleScript.
For the uninitiated, AppleScript is an archaic, frankly bizarre scripting language which has existed in the Macintosh OS since System 7, and survived through the later generations of the classic MacOS through to OS X today. Put simply, it’s a ‘natural language’ automation tool: it’s designed to help you automate the exchange of information between applications, and repetitive tasks involving similar data sets.
For my experiment in learning AppleScript, I decided to automate a task I perform quite frequently on my own machine. On any PC I own, I generally have two “junk” directories: there’ll be one
Downloads directory, and another called
Room 101, where I drag stuff from the desktop that I’m finished with and don’t feel comfortable with Trashing.
Every month or so, for the last two years, I’ve copied the contents of these directories to my external hard disk, freeing up the space on my machine’s main drive. It’s a simple, repetitive task, and it’s therefore ideal for automation with AppleScript.
You can see the results of my efforts here. There’s a lot of copy-and-pasted code here, and the
date_format() function is extremely clunky. Furthermore, it doesn’t handle errors very well: this particular script will be unable to deal with folder-merging conflicts.
However, it works, and it works well enough for me to now find regular use for it. I even built in a refinement that means that items labelled grey in
Room 101 won’t have their originals trashed: this allows me to keep the original of something I know I’m likely to need, but I still don’t want cluttering up my desktop.
It took some trial-and-error—but it works, and it’s been an interesting experiment in misguided English-like syntax. You’re free to use the code as you please: if you manage to improve on it, then please don’t hesitate to release it and let me know!