Six Colors
Six Colors

by Jason Snell & Dan Moren

This Week's Sponsor

Save 20% on the award-winning Audio Hijack with coupon code 6C20AH!

By Jason Snell

The Template Gun meets Shortcuts

Note: This story has not been updated since 2021.

I’ve written a couple of times about Template Gun, a hot-dog cannon of an AppleScript that I use to automatically expand zip archives of Logic Pro templates to use in editing projects. The script began as a simple tool to choose a template and put an unzipped copy on my Desktop, but then added the ability to use the Internet to automatically rename the folder and project to the right episode number.

But of course, we now live in the era of Shortcuts on the Mac, and prompted by my Upgrade podcast co-host Myke Hurley, I considered whether I could rebuild the Template Gun in Shortcuts on the Mac. The answer is yes—I constructed a new version of Template Gun that never once resorts to AppleScript to do its job.

Here’s a guided tour through all 54 actions that make up the shortcut, which you can get for yourself here.

What made Template Gun a tool that was just for me was that it was hard-coded to specific podcast templates of mine. If I started a new podcast, I’d need to update the AppleScript script to add support for the new podcast. With Shortcuts, I decided to make it a bit friendler by allowing configuration via a Dictionary:

Essentially, each podcast template gets an entry containing its name; inside each entry are two keys—slug and format—that determine how the shortcut acts on the template. I’ve got a bunch of my podcasts in here, but my colleagues at Relay or The Incomparable can edit this list to put in their own. The slug is just the string used to refer to the podcast in its various URLs. The format says whether the template should be automatically numbered by looking up the latest episode number on The Incomparable or Relay, if the template should be renamed to the current date, or if the script shouldn’t bother renaming anything.

I used the Import Questions feature of Shortcuts to have anyone who downloads the shortcut to choose the folder that contains their template files. Once that’s set, the shortcut has the user choose which template to extract. In AppleScript, I need to do the rest by scripting the Finder, but Shortcuts has file management built in. So the shortcut extracts the archive in question, makes a new folder on the Desktop, and loops through the contents of the extracted archive in order to save them all to the new folder.

This points out a big difference in how the two scripting systems think. Scripting the Finder is like using the Finder—you would copy a file, unarchive it, and then delete the archive file. Shortcuts instead “extracts” the archive—an action that doesn’t actually seem to do anything except offer the contents of the archive as the result. The shortcut needs to manually create a new folder for the contents, and then “save” every individual file into that folder. The result is the same—the contents of the archive are in a folder on my Desktop—but it’s a very different journey to get there.

In this section, I’m using the name of the selected template file to look up the two fields in the Dictionary for that file, slug and format.

Relay and The Incomparable differ a little bit, most notably that The Incomparable doesn’t place episode numbers in the title of its RSS feed items. So the shortcut need to use different methods to parse the sites and figure out the number of the most recent episode. For The Incomparable, the shortcut parses a file called stats.txt that will always have the most recent episode number at the very front of the very first line of the document, followed by a semicolon.

For Relay things are a bit more straightforward: the shortcut grabs the first item from the RSS feed, and match the number at the beginning of the title.

Having now gotten the latest episode number, the shortcut can act on both Incomparable and Relay podcasts in the same way. First, the shortcut adds one to the number—we want the next episode, not the current one!—and then rename the folder and any Logic Pro file contained within to be the slug plus the episode number.

Next, for podcasts where it’s more about the date than the episode number—the Six Colors podcast in particular—the shortcut instead uses the Current Date variable (custom formatted to yyyy-MM-dd) to rename the folder and Logic project.

That’s it. This is a simpler and easier to update automation than my AppleScript. While aspects of Shortcuts on Mac are still weird—that dialog box from which you choose a template is ugly—the results are impressive. Again, if you want to look at the shortcut in detail, get it for yourself here.

If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.

Search Six Colors