How I use Alfred on my Mac to automate all the things
Alfred is a little productivity app for the Mac. I’ve used it since November 2011, before it even hit v1.0; it’s now at v5.0.3.
For many years, I really only used it as a launcher. Use a hotkey (I use CMD+SPACE, normally used by OSX as a way to invoke Spotlight) and up pops a text box. Then you type what you’d like to open.
So far, so dull: though, to me, infinitely better than my hands leaving the keyboard, finding my mouse, finding where the pointer is, and then going to un-hide the app bar before looking for the Keynote icon which may or may not be there, clicking on that, and returning my hands to the keyboard.
That, by itself, was quite excellent; and depending what you type in that text box, it’ll open Google for you, or go deep into a system preference, or even lock your screen. And for many Mac users, that’s already a pretty good deal.
However, Alfred comes with workflows: a way for Alfred to run more code and tools however you’d like it to.
I found myself often doing the same repetitive thing over and over again, and I decided to learn how the workflows work. And by the looks of things, I’ve got quite a few now! This page (rather confusingly) shows all the different workflow shortcuts I’ve set up.
Keyboard shortcuts
Right up at the top, there’s a shortcut that can be fired by simply typing !pn
into wherever I’m typing. I’ve fixed it to also trigger when I type !Pn
(since my typing style sometimes means I keep holding the shift key a little longer than usual); and I’ve recently added just hitting the F15 key as a way to trigger this. (You have up to F19 on a full-sized Mac keyboard).
When I press that, a little bash script goes and grabs a little bit of text from an API on my website, which says something like
I’ll get this into the next edition of Podnews! Podnews’s newsletter currently has 25,028 subscribers, and our website’s articles have been viewed 1,600,320 times over the past month. This story might also be in our daily podcast which got 84,807 downloads in the last 30 days.
Then, Alfred pastes that text into wherever I’m typing. Hey presto, it’s super-quick to respond to someone’s email to let them know that their story is in the newsletter.
I’ve written a similar one, which is fired when I type !gp
— short for “guest post”, which politely tells people that we don’t do random guest posts or paid links, and to either buy advertising like everyone else does, or to go and boil their heads.
Now, sure you could use TextExpander or even mac OS’s built-in tool for this (System Preferences > Keyboard > Text); but Alfred lets me grab ever-changing text from a website and paste it in instead. Much nicer.
File uploads
Alfred has a thing called “universal actions”, which let you highlight a file in Finder (or on the desktop), and hit a shortcut key to see a set of actions that you can take on that file. So, here I am triggering that on a graphic on a file, and as you can see there are three specific upload scripts I’ve set here.
This runs the AWS command-line in a bash script and uploads these files (and sets their caching to be immutable). This lets me upload files to a few different places with just a couple of clicks. Previously, I’d have had to open a file transfer program like Cyberduck. Much simpler.
Hotkeys
You’ll notice there’s a few simple hotkeys on the lower right hand side. The F16 key is set to always open the main graphic file for article images, for example. F19 will always open my text editor, where I write each edition. These are the files I’m using most, and it makes sense to have hotkeys for each of these.
Exporting scripts
On the bottom, you can see two export scripts. The top one, “export slide 2”, will simply take slide 2 of my main graphic file (yes, I use Keynote for all image work: it’s all I need), export it to a jpeg file, rename it, then upload it to the fileserver, and then prime the image resizer script to produce a set of images in the right size. That’s fired by typing “export slide 2” into the Alfred text box, and removes about three minutes of fiddly work that was easy to get wrong.
The bottom one, “export artwork and audio”, I’ve written about before here: it produces artwork, renames it, takes audio files to reformat and re-encode them for various tools, and uploads the resulting images and audio files. This pulls about ten minutes of work into a script that runs for about 45 seconds: but, more importantly, does it entirely consistently. It (and the checks that I do when publishing) are responsible for stopping me from messing up on an almost daily basis.
I don’t need to use Alfred for either of these, but it’s significantly simpler to do so than go and find some kind of arcane script that I’ve saved somewhere (and Alfred backs-up its configuration files into a folder that is shared elsewhere).
Replacing bookmarks
If I need to add a press release to the website, I’m literally typing “add a press release”, which takes me to the internal page on Podnews’s home-grown content management system to let me do that. That’s nothing more clever than a bookmark; but Alfred reads both Safari and Chrome bookmarks. (And, slightly perversely, I’m currently running Firefox as my main browser, so this is helpful since I’ve very few bookmarks currently set!)
After all this, I don’t suspect I’m using Alfred to anywhere near its full capability. I’ve found the “Div” workflow, which resizes screens; and a little “toggle” workflow that allows me to put my system into dark mode or light mode for development work: but I bet there are a bunch of other tools that I could be using. I’ll just continue spotting things I’m doing repeatedly, and see if I can code that. Might be fun…