As some of you know, I watch a lot of Christmas Vacation during the holidays. I watch it so many times that I feel it is my duty to inform the world that not only have I watched Christmas Vacation, but also how many times I’ve watched it.
At first, I used a simple tally sheet in the form of a note on my phone, but that was too much work. I have this powerful phone, it should do the work for me! My first attempt at automation used a combination of Pythonista and Dropbox. It worked, but wasn’t elegant. And I’m all about the elegance.
Two years ago, I bought the Workflow app for iOS. With Workflow, I was able to write a small set of instructions that kept track of how many viewings I have completed. The Workflow had the added capability of creating my status message so I didn’t have to. All of this was under a simple tap of an icon on my home screen.
Workflow was purchased by Apple, and is now a part of iOS 12 and called Shortcuts. You can use it to automate all sorts of task, but today my goal is to keep track of how many times I’ve watched Christmas Vacation.
Show me the Shortcut
Whoa, slow down there cowboy, at least buy me dinner first. If you don’t want to wait and learn the nitty gritty, then go grab the Shortcut from any iOS device running iOS 12.
Creating a shortcut
Counting up
There is one piece of information that I need to store somewhere, the number of viewings. Shortcuts doesn’t have anyway of storing this information in itself, so I settled on iCloud Drive. Shortcuts already has a folder in iCloud Drive called, are you ready for this, Shortcuts. In that folder I store a text file named cv.txt whose contents are the number of viewings of Christmas Vacation.
The first few steps of the Shortcut check and see if the file exists. If it doesn’t, a file named cv.txt will be created in /Shortcuts with the contents of 0. If the file exists, the Shortcut sets a variable to the number of viewings, incrementing it by 1. Since the Shortcut creates the file if it isn’t there, to reset the number of viewings each year I only need to delete the current cv.txt file.
We now have a number of viewings, let’s add one to it.
And convert it to a dictionary for the next step.
Ordinal steps
I want to share out the phrase “I’ve watched Christmas Vacation for the 5th time in 2018“, replacing the number of viewings with the ordinal number. Yes, ordinal is the correct word, go look it up. The easiest way to get the ordinal was to set up a dictionary of values, where 1 equals 1st, 2 equals 2nd, 3 equals 3rd, and so on, up to 25. The Shortcut looks up the value based on count.
The above creates a dictionary, and sets the variable Ordinal to the looked up value based on Count. The dictionary is for Javascript, so the format is { “1”:”1st”, “2”:”2nd”, “3”:”3rd” }.
Verification
Once we have the ordinal, the Shortcut asks for verification to increment the number of viewings and post it. If they cancel at this step, no harm no foul, the Shortcut ends.
Selecting Post will save the current number of views to cv.txt in iCloud Drive, overwriting the current file.
Posting
Finally, the time has come to compose the status message and share it.
The Text block composes the message, using the variable Ordinal and the special variable Current Date. Current Date is a custom format of yyyy, which will be the current year. This way I don’t have to update the Shortcut every year.
Now that we have our message, I’ll use the standard Share sheet to share it to the world.