nick comer

programmer, tinkerer, learner

Using a mild Twitter addiction to actually get things done

Modern mobile devices contain a myriad of distractions and addictive platforms. My vices are Twitter and TikTok.

For Twitter, I have been a long-time user and I have curated a timeline of a lot of cool/smart tech folks that keep me up-to-date with what is going on in my industry so, it has some mild utility. But, I would be okay if I used it less.

I recently gave in and picked up TikTok and… holy moly it is pretty addictive. No real utility in this besides pure entertainment and just being able to turn my brain off. I understand the points being made about how this form of consumption long-term is probably not good for your mental health. So making sure it is limited is just good sense.

So, being honest with myself, I have recognized that I spend a bit too much time just scrolling around in these apps when I could be doing other things that help with my physical and mental health.

That means that I should just marshal some self-control and just tone down the usage of these apps with nothing but my will, right?! Wroooong! We’re gonna make the technology do it for us!

Reining in the addiction

It started one day when I realized that I would routinely open Twitter only a few minutes after waking up and start scrolling. To me, that was over the line and I needed to do something to make that impossible.

I have an iPhone. Compared to an Android device, the ways it can be customized to behave differently are more limited. There is, however, Shortcuts!

Shortcuts are programs that can be built visually using an app and then run on any iOS device. There are a few rough edges, but mostly the platform (IMO) is a great success in letting folks automate things on iOS.

iOS Shortcuts can be triggered in a variety of ways. For the use case of “blocking” apps, a shortcut can be automatically triggered when a particular app is opened. Like this:

Screenshot of shortcut automation setup in iOS

The initial rule was simple: don’t let Twitter be opened before noon. Using Shortcuts, this can be built in a simple way:

Screenshot of an iOS shortcut implementation that will prevent app usage before noon

The shortcut starts by taking the current time and formatting it to just the hour (can’t see it from the screenshot). That string is passed to an “if” block that is configured to interpret the strings as a number (also not seen in screenshot). The condition on the “if” block is testing to see if the current hour is less than or equal to 12.

If this condition is true, it will forcefully return to the home screen and then show a notification that shames the user for their lack of self-control, like so:

Awesome! We have the core behavior implemented: limit the use of addicting apps given a set of conditions.

Once I initially implemented this, it worked perfectly. I would absent-mindedly try to open it in the mornings and then my phone would stop me and remind me to enjoy my morning without Twitter.

Being so pleased with the results I wanted to tinker more, and then it occurred to me to not just limit the usage of addicting apps, but use them as an incentive to form other good habits.

Using the addiction to get things done

The if block in our first version can be re-used to check almost anything an iPhone can retrieve; the possibilities seem quite large.

The general idea behind the next version of the Shortcut is that I want certain daily tasks/activities to be finished before we let Twitter or TikTok be used.

Walking is a really good daily activity. It has been shown to promote brain health and physical health. I also have an Apple Watch that allows me to track my activities. And that activity data is stored on my iPhone.

Now there is a new set of rules to have access to my precious apps (all must be true):

  • MUST be after 12pm
  • MUST log a >= 1-mile walk for the day

The implementation of this gets a bit more challenging. Implementing logic in Shortcuts is possible with simple if blocks. But there is a lack of logical conjunctions in Shortcuts (&& or ||). So, instead of assembling this:

if (bool_1 && bool_2) {

You would need to implement it like this:

if (bool_1) {
  if (bool_2) {

And without a || conjunction, it gets even weirder where you need to duplicate the code over multiple branches to implement:

if (bool_1) {
} else {
  if (bool_2) {

With that in mind, the implementation should be done in a certain way to avoid weirdly nested logic. This can be done by interpreting the requirement in the negative (“you did NOT do this, therefore…”) and making each if block do the rejection logic, like this:

if (!afterNoon) {
if (!hasWalked) {

Still not great because the “therefore” logic is duplicated.

On a positive note, Shortcuts can invoke other Shortcuts and provide input and receive output. This gives us the ability to encapsulate business logic as “functions” and simply invoke them from other Shortcuts. This helps immensely in keeping Shortcuts easy to maintain and grok.

This is what the updated Shortcut looks like:

Screenshot of an iOS shortcut implementation that will prevent app usage before noon and before a 1 mile walk has been completed

The logic on the top part is pretty much the same as the first version. But, if it activates the first if block, it will cause the Shortcut to early exit. The 2nd if block is the logic for checking if a walk has been completed. All the logic for “did walk today?” is neatly encapsulated in another Shortcut, like so:

Screenshot of an iOS shortcut implementation that will check if a 1-mile walk has been completed

iOS, by itself, weirdly does not have any APIs for looking for workouts in its own “Fitness” app like this, so the top block is a third-party app Toolbox Pro which is amazingly useful and worth the PRO version and tipping the developer.

Putting all of that together and, voilà!

Now, addiction to apps has been turned into something motivating and evens out the unhealthiness of these apps.

The catch

All this is nice, but obviously, it can be bypassed. Nothing stopping me from simply disabling the automation, then no more nagging. Using this on someone who does not want this to be enabled will obviously result in them breaking and getting around it.

So if this is being done for one’s own good, then it helps to remain honest with yourself and to not try to bypass these checks.

Personally, I’ve done really well with resisting the urge to just disable the checks. I’ve started regularly having the thought to myself, “better go for a walk or else I won’t be able to use Twitter today.” So, this setup is working for me in a really great way. I have even started experimenting with versions of this that require a set of daily reminders to be checked off in order to allow app usage (daily reading, stretching, etc.).

The possibilities for this “hack” are quite numerous and fun!

(Discuss on Hacker News)