apple shortcuts

Apple's Shortcuts And No To Social Media

1 Nov 2022

This week a friend of mine with whom I have a WhatsApp group, proposed the group to install the app Be Real so that we could share moments of our day instead of just chatting on WhatsApp. I honestly dislike photo and video-sharing Social Media apps, and just looking at Be Real gave me the shivers.

My initial proposal was that we could also share photos in that group, by our own will, but I know people will eventually forget about it, and the time randomness of Be Real actually had some appeal to me.

I started looking into what could I do to mimic that randomness without having to install Be Real. My first guess was to look into the WhatsApp API to create some kind of bot that could send one message per day at a random time. I eventually stumbled against WhatsApp Business API and some services to create my own bot, but I was not willing to spend much time creating a bot or hosting some bot for any money.

My second guess was to send a message every day asking people to share pictures of their day. Again, I would definitively forget about it every single day. And an alarm would be so painful to have every day. Could I automate that message somehow? That's where Shortcuts comes in this history.

Shortcuts (previously Workflow) is an app that not so many iPhone users use or even know about its existence. But it is one of the most powerful apps on the iPhone. It basically allows us to do two things: named voice-over commands (shortcuts) that execute a set of operations; or automations based on the time of the day, incoming messages, app behavior, alarms, etc.



This basically gave me a cron server running in my pocket. All I had to do was to program that server. I wanted to send this message once a day from 9AM to 8PM but randomly, to mimic Be Real which sends unexpected notifications. The problem was divided into 2 steps: 1) calculate at which hour the message was getting sent, 2) send the actual message.

My idea was to calculate the random hour in the morning and have it monitored during the day. After some investigation, I figured that this random number (9-20) could be stored in a file. The first automation consists of generating a random number between 9-20, store into a JSON dictionary under the key "random" and storing it in a local file (also called random[.json]). The file necessity is to be able to share data between multiple automations. This one runs every morning at 08:50AM.



The second automation is actually 12 automations. Since I didn't put much effort into creating these I ended up creating 12 equal automations that each run once between 9AM and 8PM, instead of a generic one, which I'm sure is possible. The automation consists of: first, reading the previously mentioned random[.json] file from memory, and getting the dictionary ({ random: x }) from there; second, comparing the random value with the hour being checked (from 9 to 20). Shortcuts has a programmatic interface that even allows for loops and conditionals, which allowed me to send the aforementioned message if the random and the hour match.



And yes, Shortcuts also allows interaction with other apps in the iPhone, given the permission to do so! One of building blocks of this automation is exactly sending a WhatsApp message which can be done by searching it in the Apps section, or the Send Message in the Categories section.



And just like this, I prevented myself from installing Be Real and have a similar experience with WhatsApp where I have the same friends who were willing to share daily moments. In the process, I learned that I have a powerful server in my pocket capable of doing great stuff. I leave you with an example of the WhatsApp automation with a fake group (to protect the identity of my friends).



Hope you enjoyed it.