Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want a script (bash/zsh/ruby/...) to run at boot time in OS X. What's the most simple way to do this, without messing with xml/plist files, and preferably not needing to make a meta AppleScript.

share|improve this question
up vote 4 down vote accepted

MacOS X uses Vixie cron, which has special meta tags for launching at reboot time. See the man page for the file format.

something like:

@reboot /path/to/

in your crontab would work. I'm not sure that this a better solution than launchd, you probably have more meta tools that look at launchd than cron.

share|improve this answer
Love it, you proved me wrong :-) Although cron on OS X is not that great with logging by default (there was a topic on that just a few days ago). – Daniel Beck Feb 14 '11 at 16:16
this is perfect. – John Bachir Feb 14 '11 at 18:59
Note that cron, at, and so on are to some extent deprecated in OS X. I can't find an explicit statement of that in the various docs, nor do I know how aggressively deprecated they are, but launchd does seem generally preferred. See the launchd documentation for an introduction. – Norman Gray Feb 15 '11 at 18:55
plist won't work for me - this works like a charm - thank you! :-D – Bruno Garett Nov 30 '15 at 1:18

In case you change your opinion:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Store as com.superuser.245713.plist in /Library/LaunchAgents/ and make root:wheel the owner/group.

share|improve this answer
It's arguably better to put it into /Library/LaunchAgents rather than /System/Library/LaunchDaemons since /System is OS-specific stuff and the one under /Library is used more for third party stuff. Also, LaunchDaemons "should contain items that will run as root, generally background processes" where as LaunchAgents "run as a user or in the context of userland". The source for those quotes is a great article on launchd that I consult for launchd questions. – Doug Harris Feb 14 '11 at 16:19
@DougHarris Thanks for the suggestions! I have to admit I was just typing this ad-hoc -- while I usually test my solutions, I wasn't willing to restart my machine for this. – Daniel Beck Feb 14 '11 at 16:22
This is very nice, although I like the Vixie cron solution better :) – John Bachir Feb 14 '11 at 18:59
Actually, it should be put in /Library/LaunchDaemons. Agents only run inside a user session, i.e. they won't run (or more precisely, become eligible to run) until someone logs in, will run again every time someone logs in, and always run as the currently logged in user. Daemons run (/become eligible to run) at boot, and while they normally run as root, can be run as some other user with the UserName key. – Gordon Davisson Apr 25 '12 at 4:56
@the0ther The web doesn't forget. – Daniel Beck Mar 24 '14 at 21:23

There are also Login Hooks if you would prefer the script to run (as root) when a user logs in rather than when the machine is booted.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .