Run MARIO RUN or any other app from Workflow with Pythonista

Anything is possible with Pythonista and some private APIs hocus-pocus (:

Workflow is the ultimate way to achieve every possible level of automation on iOS. Much has been written on the app, namely by Vitici, so if you are not familiar with it, go check it out. It’s amazing.

Pythonista (Or it’s new version Pythonista 3) is another great app, that gives you a complete offline Python IDE in your iOS device.

Workflow allows opening any URL as part of your workflow, thus giving us the power to basically launch any app that supports URL schemes. But what if the app we wish to launch does not accept any URL scheme? This is where Pythonista comes in. One of the best things about Pythonista is that it allows communication with the runtime environment and access to the entire library of iOS frameworks.

So let’s assume we like MARIO RUN, but we like it a bit too much, and every time we start playing it we realize half an hour later that we just spent 30 minutes jumping over mushrooms and hitting the “Retry” button a bazillion times trying to get all the purple coins (or the dark green ones if you are really sick…). What we want is for the phone to remind us after 5 minutes that we’ve played enough and it’s time to do something productive.

To do this, we create and run a Workflow from the home screen. Obviously we give it the same icon as the game, and we can call it “Mario Break”

Our Workflow will:

  • Add a reminder for 5 minutes from now, to hint to us that we’ve played enough.
  • Launch Mario.

The first part is easy, but for the second part we need the help of Pythonista to run a script that would launch the game by calling it’s Bundle ID.

This is the script we ask Pythonista to run:

from objc_util import *
from ctypes import *
libobjc = CDLL('/usr/lib/libobjc.dylib')
LSAppilcationWorkspace = ObjCClass('LSApplicationWorkspace')
workspace = LSAppilcationWorkspace.defaultWorkspace()
workspace.openApplicationWithBundleID("com.nintendo.zara")

(When you add the script to Pythonista make sure you save it under the name “mario.py”!)

Yep, apparently Mario’s BundleID is com.nintendo.zara ¯\_(ツ)_/¯

And this is our Workflow:

(Get the Workflow here)

Have fun playing Mario responsibly! (: