11

Hello I'm using Mac OS X 10.6.8. How can I set some simple Terminal commands to run on start up as if I was opening up Terminal and putting those commands in myself? I basically need to start a few server daemons on start up. The commands I use in Terminal to manually start them look like sudo ruby myrubyserverscript_control.rb start. I apologize in advance if this is super obvious or already answered on here a million times in some way I don't know enough to recognize.

pitachip
  • 965
  • 3
  • 7
  • 24

2 Answers2

13

Here are two different things:

  1. you want run a script after the system startup (boot), or
  2. when you logging in

for run a script at boot, you should put one XML config file into /Library/LaunchDaemons (and the launchd process will run the script at the boot time)

for run a script after you logging in - see this: https://stackoverflow.com/a/6445525/632407

Community
  • 1
  • 1
clt60
  • 62,119
  • 17
  • 107
  • 194
  • I've never written an XML config file before. I do see two XML files in my LaunchDaemons folder however. Would it be as simple as making another one of those except where I replace the 'Program Arguments' with the command I want executed? – pitachip Sep 24 '12 at 13:53
  • 1
    Eh... not really. You can experiment, but strongly advice to read this: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html and understand what you do. If you have Xcode installed, you can create the file (it is property list XML) inside Xcode. But you can create it with any text editor. Need change the "Label" to filename to your and here are many things. Sry, but it is hard to tell exactly what you should do, without knowing more. (e.g. how your script acts, have where want error messages, want periodic run and many many. see the link) – clt60 Sep 25 '12 at 17:16
10

Open System Preferences and go to the Users and Groups / Login Items tab. You can add a scipt with the + button or drag it to the list of items. Usually scripts end in .command that are used in this context but they are just bash scripts. I suppose you could use any script that is executable and has the correct #! line.

Will
  • 4,585
  • 1
  • 26
  • 48