News

Ventura and the at job

A screen with code

Update: syntax correced, thanks @monkeydom and @teilweise

Nerd content incoming!

The at job is a little helper that executes things on Unix-like operating systems in the background, in the future. Automatically. If I want a command to be executed once at a specific time in the future, even on a specific date, then good old at is my tool of choice.

This all happens at the command line and it looks something like this:

at now + 10 minutes <<< command ('here string' syntax)

macOS is also a Unix-like operating system under the hood, so it supports at.

Here's what I particularly like about at:

  1. It is part of the operating system and doesn't need to be installed or maintained
  2. It fires the commands even when the device (in this case a M2 MacBook Air) is sleeping. And it doesn't matter whether it's connected to the power supply or on battery.

Unfortunately, at is a bit hidden and entrenched behind various security mechanisms. But with a couple of tricks it can be teased out, without resorting to hacks. Took me some time to figure it out, but here's how it works:

  1. Load the appropriate LaunchDaemon:
    launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
  2. Enter allowed usernames in /var/at/at.allow, one per line
  3. In System Preferences > Security & Privacy > Full Disk Access add /usr/libexec/atrun to the list

I had items 1 and 2, but couldn't get it running and almost gave up at that point. Luckily I stumbled across item #3 somewhere in the depths of some comments. Worked after that. Might have done a safety restart. The side effects of the new macOS security measures are not always well (or at all) documented.

at -f party.sh now + 45 minutes