January 9, 2025
The best punch cards are the ones you don't have to punch
TLDR: I made virtual punch cards!
Back in the day at the tai chi club, we used punch cards to keep track of how many classes people attended. After 10 punches, you had to pay for 10 more classes.
Then they put me in charge.
I didn’t want to be rooting around a box of cards at the beginning of every class as I tried to keep track of who had shown up that day. My solution was virtual punch cards on a web page — designed to look old-timey with CSS and using names and numbers fed to it by JavaScript.
But that meant the unpleasant prospect of updating JavaScript after every class, so those cards sat idle for many months. Meanwhile, I looked for a way of keeping track of people taking classes that didn’t involve real punch cards.
My natural inclination was to turn to technology — maybe a spreadsheet or some kind of app. I went through a lot of ideas that were way more complicated than they needed to be. Then I learned about tally apps.
Tally ho
Do a search on “tally” in the App Store, and you will find yourself swimming in suggestions. A tally app basically just counts things for you, so of course it’s easy to develop, and there is a plethora of them.
Still, counting was really all I needed to do. Each person attending a tai chi class is a tally in a list of tallies. If they show up, I tap the plus button beside their name, and thus update the number of classes they have attended.
After trying several tally apps, I settled on one called Tally, by Agile Tortoise, that rises above the rest. It does that with support for Shortcuts.
The Shortcuts app, which comes free with Apple devices, allows you to put together a series of actions which can be invoked with the press of a button.
Jason, meet JSON
The shortcut I made uses one of the Tally app’s own actions to get the tai chi club’s list of tallies. Other actions convert this into a JSON file and save it to iCloud Drive. This is a handy spot for a file because I can easily access it with my Mac.
It needs to formatted as JSON, so I can upload it to our website’s server where JavaScript uses it to spit out virtual punch cards with the correct names and numbers. Yes, it really is just a bunch of names and numbers, but I wanted these names and numbers to be displayed in a way that feels familiar. And punch cards are familiar.
I did this with the magic of JavaScript, but there was still one piece missing. I didn’t want to have to upload the JSON file after every class. It would be more work, and what if I forgot?
The solution was more automation.
I needed a way to take the JSON file from iCloud Drive and upload it the server. If the JSON file is updated by the Shortcuts app, that means that tallies have been updated, and the virtual punch cards also need to be updated.
That syncing feeling
A good old app called FreeFileSync came to the rescue. I showed it where to find the JSON file on iCloud Drive and where to find the equivalent file on the web server. With this information, it created something called a batch run that keeps the two files in sync — double-click it, and it runs.
I didn’t want to have to remember to double-click it, so I created an Automator script that does this for me. Automator is yet another automation app that comes free with your Mac. Again, though, that would mean clicking the script to run it. So I went deep into the bowels of Terminal and instructed a daemon called launchd to watch the JSON file. If it detects an update, it executes the Automator script, which in turn executes the FreeFileSync batch run.
I wish I could have skipped the intervention of Automator, and had FreeFileSync work directly with launchd. Alas, this was taking way too long, and Automator was the easy way out.
The only catch is that the Mac has to be awake in order for launchd to work. It’s a small price to pay, but as an incurable tinkerer, I may yet find a workaround. (Edit: Looks like pmset is the most reliable way of waking your Mac on a recurring schedule.)
To top things off, this whole chain of automation is fired off by a setting in the Shortcuts app that makes the shortcut run when I close the Tally app on my iPhone.
Nerd creds
It seems like there should be an easier way. Ideally, you should be able to do all this from the Shortcuts app on the iPhone. There is a Shortcuts action that is supposed to connect to a server and run a script to upload files, but I could not make it work. None of ChatGPT’s suggestions panned out. Questions left in Apple and Reddit forums went unanswered.
The system I came up with could only be appreciated by an automation nerd, but it works.