2025: AI everywhere, yet a reboot still saves the day
Intro
While working on this article for SerpApi, the leading Search API provider, I tried to automate my scripts to run on a daily basis. Surprisingly, this task turned out to be much more difficult than I expected. Here’s the path I followed.
Launchd or Cron
Launchd is Apple’s recommended tool for managing background services and scheduling tasks.
Cron is a shell command for scheduling a job to run periodically at a fixed time, date, or interval.
Unfortunately:
Cron is not recommended for macOS because launchd is the modern, preferred system for scheduling jobs, offering better integration with macOS features, such as running tasks when the computer wakes from sleep. Unlike cron, which fails to run jobs when the system is off or asleep, launchd will execute missed tasks upon system startup. Additionally, recent macOS security features, such as Full Disk Access protections, make it increasingly difficult to get cron jobs to run correctly without granting permissions.
Script
To illustrate the issue, I’ll use a simple Launchd
agent.
User agents should be placed inside the ~/Library/LaunchAgents
directory, so I’ll use nano to create and edit the file:
nano ~/Library/LaunchAgents/local.test_daily_job.plist
Here’s my XML config:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<!-- This will be the unique identifier for our new agent -->
<string>local.test_daily_job</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>osascript -e "display notification \"$(date)\" with title \"Time\""</string>
</array>
<!-- This script is scheduled to run daily at 12:40 -->
<!-- Initially, set the time to 5 minutes ahead of your current time. -->
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>40</integer>
</dict>
</dict>
</plist>
Once done:
- Press
CTRL+O
to save the file - Press
ENTER
to confirm the filename - Press
CTRL+X
to exit the editor
Don’t worry - nothing will run just yet.
To run the job, use the following command:
launchctl load ~/Library/LaunchAgents/local.test_daily_job.plist
At the scheduled time, you should see a notification appear in the top-right corner of your screen.
Time zones
Now, let’s imagine you travel to a different time zone. You close your laptop, take it on a flight, then open it at your destination and update the timezone.
One day you might discover that your launchd
agent is still running according to your original time zone, so you end up scraping news at 10:43 a.m.
Even though the config still says 12:43.
Solution
At first, I thought macOS kept two different clocks — a motherboard time and a system time — so I searched the internet and even asked AIs for a fix. The truth is... there’s only one clock >.<
For weeks, I was wondering why my setup wasn’t working. Then, about a week ago, my external ExFAT disk stopped mounting again (as it occasionally does). I really hate rebooting my laptop, but this time I had no choice. To my surprise, rebooting didn’t just fix the disk — it also solved my launchd timezone issue!
Why did this happen? Well, launchd
is the init process (PID 1), so it only picks up the new timezone when restarted, which happens if you Restart
or Log out
.
So yes, it turns out all those classic support tickets were right: “Sir, please restart your computer.”
Maybe AI should keep the tradition alive and start every troubleshooting session with: "Sir/Madam, did you try restarting your computer?" :)
And that’s the end of the story — and three sleepless nights.
Let’s travel (with working timezones!) and use SerpApi anywhere, since it supports searches across many countries and languages!