
Automating Blog Images using Alfred File Actions

This automation is really ugly, but it makes my life so much easier. Automation can make you faster, but it can also make you more consistent.
When I'm working on a blog post, I'm frequently pulling airdropped photos from my phone, screenshots, and random illustrations to put in the current draft. All these artifacts need to go to the right folder in my git repo.
The correct file location for an image (for me!) is:
/images/articles/{YYYY}/{MM}/
Especially early in the month, that folder doesn't always exist. Worse, it has duplicates in both the source
and build
folders of my static site… so it's often hard to find the right folder even using Alfred's fast file search. I usually end up typing the name of a recent image, opening the containing folder in Finder, then navigating and doing it manually. I'd often put the image in build
instead of source
, or other mistakes.
No longer!
I finally wrote a tiny script and added it as an Alfred Workflow as a File Action. That means if I select any file on my computer or find it in Alfred, then hit Tab to act on it, I can select my workflow with speed.
The workflow looks like this in Alfred:

And the bash script is stupid and simple.1
# I choose to pass the arguments as {query} instead of
# the default $1
repo=$HOME/src/github.com/evantravers/evantravers.com
folder=/source/images/articles/$(date +%Y/%m/)
mkdir -p $repo$folder
# the OSX default `cp` command doesn't have this argument.
# I'm using `gcp` from "brew install coreutils"
/usr/local/bin/gcp -t $repo$folder {query}
Now… no matter whether the folder exists, and no matter how I find the image… it's a one keypress away from being in exactly the right place. 👍
-
The trick for using GNU
cp
on OS X I got from this ask ubuntu question. ↩
Changelog
-
2022-06-08 11:31:29 -0500Rename articles
-
2020-09-03 14:04:25 -0500Fix link to ubuntu question
-
2020-09-03 11:33:03 -0500New post: quick automation