We’ve become accustomed to staying in control of our Macs. Before the days of Time Machine, and in its early versions, backups usually meant that you couldn’t do much else on your Mac until they were done. We now expect to be able to work normally, whether our Macs are backing up, maintaining a large database, downloading updates, or similar.
A large proportion of Macs are now laptops, and much of the time they run on their battery power. We expect their batteries to deliver good performance for long periods before they need to be recharged.
One key feature to help our Macs operate to meet those expectations is the ability to run background tasks in the background, without interrupting our activities, or discharging the battery prematurely. macOS provides a whole system to do that, in Grand Central Dispatch (GCD), but then makes it impossible for users to access.
Let’s say that you want to adjust the frequency of Time Machine backups so that they occur every 90 minutes, or two hours. macOS still doesn’t allow you to do that, so you must use a third-party tool. When you do that, the normal mechanism for making those backups, which operates through GCD, is turned off, and your backups are made using a scheduled process and
launchd, which does not use GCD. The same is true for any scheduled process which you install through a LaunchAgent or LaunchDaemon: it is triggered and run by
launchd, according to the clock, and not by GCD.
Software developers can code in access to GCD in their products, but until now there has been no way for a user to run their own tasks as GCD background activities.
Here is one way that you can: DispatchRider. This is an initial experimental alpha release which appears stable and well-behaved, but is a long way from even its first beta release.
DispatchRider is an app which must be left running so long as you want it to run background tasks using GCD. It has a small footprint which is used to manage those background tasks, each task in its own window.
Open the app and (if it does not itself do so) open a new window using File/New. To schedule a task, enter the full path to the command in the Command box. By default it is set to run my tool Blowhole, which simply writes an entry into the log.
Enter any options or parameters needed by that command in the Params box. Separate the parameters using
&arg: So, for example, to pass the parameters
-s 42 to blowhole, enter in the Params box
In almost all cases, you will want to repeat the command at regular intervals; ensure the Repeat every box is ticked for that, and enter the integer number of minutes between the times that your task will be run. When you have edited that figure, press Tab or Return to confirm that change. Generally speaking, you should not use this to run activities which need to be run more frequently than once every 10-15 minutes, although GCD will still try to oblige.
The Quality of service popup menu can be left set at
'default', or you can change it to any of its other options.
userInteractive gives the task highest priority, and
background is the lowest. You can leave the Tolerance setting at 0, which uses the default, or set it to a positive integer if you prefer. Again, when you have edited that box it is important to press the Tab or Return key to confirm the change.
Once you’re ready to set the task running, click once on the Start button. DispatchRider will then assemble the task, and pass it to GCD to manage. Each time it runs, the number above the two buttons will increment by one, so that you know that it is running. The app also writes a simple message to the log, reading
DispatchRider task ran.
When you want to stop the task, click on the Stop button. Closing the window or quitting the app will also stop all running tasks.
You can open as many windows as you like, configure each to run a different task at different times, and set them all going. So long as you leave those windows open, and DispatchRider still running, GCD should continue to run those tasks.
Version 0.1a2 of DispatchRider for macOS Sierra 10.12.4 and later is available from here: dispatchrider01a2
I welcome your comments, suggestions, and reports.