Home/Q&A/launchd or cron: which should I use for scheduled jobs on a remote Mac?

launchd or cron: which should I use for scheduled jobs on a remote Mac?

Updated · airankrush

Direct answer

Prefer launchd. cron still works on macOS, but it does not make up for a missed run and is stopped by the privacy system when it touches protected folders. Jobs that operate the interface especially belong in a user-level LaunchAgent.

Basis

  • launchd is macOS's own job manager; cron is kept for compatibility. A launchd job triggered by calendar time will run once after wake if the system was asleep at the scheduled moment; with cron, a missed run is simply missed.
  • Entries in ~/Library/LaunchAgents run inside your login session, so they can show dialogs, send Apple Events and do UI scripting. Processes started by cron are not in that graphical session and often fail when they call osascript to control an app.
  • Privacy permissions are counted by who started the process. When a cron job reads Documents, Desktop or other protected data, the permission is requested for the cron system program itself, and many people end up giving it Full Disk Access, which opens the permission very wide.
  • A launchd entry can state the log paths, whether to restart after a failure, and the run interval; with cron you have to script all of those yourself.

Information as of .

Boundaries: when the answer is different

Use only the LaunchAgents folder in your own user directory. Do not touch entries in the system-level folders: the platform's management and remote-access components live there, and changing them can leave you unable to connect. User-level jobs start only after the account has logged in, and whether the machine logs in automatically after a restart depends on the delivery configuration, so ask support to check it and do not change login or encryption settings yourself. The machine is not meant to be shut down during the rental, so the difference in making up missed runs mostly shows around maintenance restarts. A mistake in a launchd property list usually means the job silently never runs; after loading it, confirm the entry exists with launchctl list and read the log.

How to do it

  1. Put the command into a script, write full paths at the top, and do not rely on environment variables from an interactive terminal.
  2. Create a property list under ~/Library/LaunchAgents with a label, the script path, the trigger time and two log paths.
  3. Load it with launchctl, then find the label with launchctl list.
  4. Trigger it by hand once, and confirm there is output in the log and the system permission prompts have been dealt with.
  5. Check the log again after one real trigger time has passed.

Use case

This question belongs to the use case: iMessage, AppleScript and Shortcuts on a rented Mac mini: it runs, but Apple decides about your account

Other questions in the same use case:

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All Q&A