[Tip] Running shortcuts consistently for a long time

Changelog


Shortcuts can keep running for a very long time, more than several hours or even days. Here are some exceptions:

Automation

  • Runs only up to 4 minutes on iOS/iPadOS if you manually add actions (including Run Shortcut)
  • Runs much longer if you select an existing shortcut to run

Siri

  • Runs only up to 15 seconds
  • Runs much longer if you add Dismiss Siri and Continue

iOS/iPadOS

Shortcut execution becomes slow if the screen is off for more than 10 seconds and the device is not connected to power. ‘Wait 1’ can take up to 5 minutes, for example. There are several ways to run shortcuts consistently over a long period of time:

Charge device

Shortcuts do not slow down when the device is locked if it’s charging over cable. It looks like they slow down if charging wirelessly even when Always On Display is on.

Keep screen on

The Open App or Go to Home Screen action keeps your screen on and delay the auto-lock timing. You can use the Get Current App action to avoid switching to a different app. You will need to do this at least every 19 seconds (in case auto-lock is set to 30 seconds) to prevent screen flicker.

The following shortcut keeps the screen on for 10 minutes, and you can freely switch to other apps:

long01

Play background sounds

Playing music or background sounds prevents shortcuts from slowing down even when the screen is off and the device is not charging. You can set the background sounds volume to 0 in the beginning.

You need to run the Turn Background Sounds On action every 10 seconds, because it automatically turns off when you put on or take off your earphones.

The following shortcut runs for 30 minutes even when the screen is off:

long02


macOS

To keep your Mac from going to sleep while running a shortcut, you can run the following command at the beginning:

/usr/bin/caffeinate -d -w $(/bin/ps -A | /usr/bin/grep 'BackgroundShortcutRunner$' | /usr/bin/awk '{print $1}' | /usr/bin/tail -n 1) &

long03

3 Likes

Thanks for this. Interesting. With the first two I’m a little unclear on how you suggest to use those. Is it to have that running and then automated shortcuts will run better or to put it at the start of a longer shortcut to make it more efficient and ensure it completes?

Do you mean the first two screenshots?

Long-running shortcuts usually do something, wait a while and then do something else. Or repeat it. In the former case, you put either one between the two tasks. In the latter case, you’ll need to put either within your main repeat loop.

The first example would be useful if you need to keep the screen on while running the shortcut, for example, taking a screenshot every minute for a long time. The second one can be used when you don’t need the screen on.

Yes understand now. Thanks for the extra detail.