December 10, 2016 at 8:23 AM by Dr. Drang
Effective automation doesn’t always mean writing a script or macro that performs all the steps in a process. Some of my most useful automation workflows are hybrids, set up so I do the parts that require thought and judgment and the computer does the parts that are rote and repetitive.
For example, in my job I take a lot of photographs. Normally, I rename and organize the photographs according to the date on which they were taken. This requires essentially no input from me. The date is stored in the metadata of the JPEG, so a script can use that to determine both the new base name of the file (to be followed by a sequence number) and the folder into which it’s placed.
Sometimes, though, I want a further level of organization. If I’ve inspected several pieces of equipment on the same day, I’d like them organized in subfolders according to subject. You might think this is a simple matter of finding the boundaries—here’s the last photo of Part A and the first photo of Paart B—and selecting groups of files with continuous sequence numbers to be selected and dragged into the appropriate subfolder. Quite often that does work, but the photos aren’t always as neatly segregated as that. When the subjects of the photos are more jumbled, and I have to look at each one to determine where the appropriate subfolder, a script that works with me to do the filing as I make the decisions can be a real timesaver.
Let’s say I have a folder with a few hundred photos taken of four items on a particular day. To review the photos, I open the folder they’re in, set it to full screen mode, icon view, and jack the icon size up so I can get a good look at the previews.
Within this folder, I’ll have subfolders for each part, which we’ll call Parts A, B, C, and D.
In theory, I could scroll through this window, selecting photos and dragging them into the subfolders named after them. But the problem with that is the folder icons aren’t visible. There’s no good way to get to them quickly. Even if I abandon full screen mode—which I really don’t want to do—and use two windows, one for the photos and one for the folders, dragging is relatively slow process, especially when you have to do it dozens or even hundreds of times.
My answer is this simple little AppleScript:
applescript: 1: tell application "Finder" 2: set addressFolder to target of front window 3: set targetFolder to folder "Part A" in addressFolder 4: set selectedPhotos to selection 5: move selectedPhotos to targetFolder 6: end tell
I set it up in a Keyboard Maestro macro to be triggered when I type ⌃⌥⌘A, and it moves all the selected files into the “Part A” subfolder. I have similar macros set up for the other subfolders. Whenever I have a big photo sorting job to do, I go in and edit these macros to make the folder names (and the keyboard triggers) match the subfolders for that project. I suppose I could write a script that reads the names of the subfolders and creates these scripts automatically, but I haven’t gotten around to that yet.
There may well be a direct Keyboard Maestro command for doing this. I’m doing it through AppleScript because I wrote this a long time ago, back when I was using FastScripts instead of KM, and just haven’t found a compelling reason to search through KM’s actions to find the equivalent. This works perfectly well and is more portable than a KM-specific solution. If the Keyboard Maestro people decide to close up shop tomorrow, I could transfer the script back to FastScripts or to any other AppleScript-supporting utility.1
The process of filing photos still requires lots of input from me, but there’s no way around that. A script can’t decide how a photo should be categorized. What a script can do is the half of the job that requires no thought but is awkward for me to do.
Of course, if AppleScript itself dies, I’m up the creek. It’s easy to move files with shell scripts, but they don’t have the visual connection to the Finder (
set selectedPhotos to selection) that AppleScript has. ↩