tags:

views:

25

answers:

2

I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).

+1  A: 

There's an option to add applications etc that need to start at login, you could try writing a shell script or an apple script thing that launches terminal and runs ruby my_ruby_script.rb, or possibly even just add my_ruby_script.rb to this list after adding a #!/bin/env ruby line to the top of that file. http://support.apple.com/kb/HT2602?viewlocale=en_US gives precise instructions as to how to add an application to be started at login.

If you need to use AppleScript to actually start a terminal application (I believe this is not the case, but I am not in front of my mac now and hence can't test), just create an applescript file with something like

do shell script "ruby <path>/my_ruby_script.rb"

Hope this helps

Aurojit Panda
A: 

As Panda said, add:

#!/bin/env ruby

to the begining of the file, and then you could add a reference to your file inside ~/.bashrc or ~/.profile or even /etc/profile , depending on your needs.

Check this out: http://stackoverflow.com/questions/3484429/profile-and-bashrc-doesnt-work-on-my-mac/3484472#3484472

karlphillip
The problem with adding to ~/.bashrc or ~/.profile is that on OS X neither is executed until the first terminal sessions is started. Also it will execute every time one launches terminal. My understanding was that this was not what was wanted.
Aurojit Panda