Link to home
Start Free TrialLog in
Avatar of chipped
chippedFlag for Australia

asked on

Run Python script on startup

Hey,

I want to run a python script on startup in OS X, elegantly. At the moment, I use the code below which leaves an apple script icon which says "Application (not responding)"

Below is the code for the apple script and a screenshot.

Cheers. screenshot20110218at101.png
do shell script "python /users/ashsaba/sick-beard/sickbeard.py"

Open in new window

Avatar of chipped
chipped
Flag of Australia image

ASKER

Oh yeah, I save the code as an Application, then add that to login items.
Avatar of et01267
et01267

This sounds like the python script is not exiting cleanly, and is "hanging" around.  It could also have something to do with the environment the script is executing within.  For example, Applescript always uses /bin/sh as the shell to run commands within, regardless of what your terminal shell may be.

I presume that you have run the script successfully from a terminal, and that your script application works correctly when you launch it manually?
Oh, I guess Applescript is waiting for output from your shell command, and this never happens.

Perhaps putting a '&' at the end of the command will allow it to fork and the Applescript will then complete.  As in

do shell script "python /users/ashsaba/sick-beard/sickbeard.py &"
Avatar of chipped

ASKER

Thanks.

The python script is actually an application that is based on python, so it's always running.
ASKER CERTIFIED SOLUTION
Avatar of chipped
chipped
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Interesting.  What didn't work when you used the Applescript ?  
There are a couple of ways that I have done this in the past.  I have noticed that if I wrap my python script in an .sh script with all the proper environments loaded that I rarely if ever have a problem with a hang'n app.

What I mean is:

create startSickBeard.sh

chmod 775 startSickBeard.sh

Then as et01267 says, run sickbeard.py with the '&' at the end, but put the full path to your proper python.  Just in case you have more then one installed python(s), bash might not start the same one you would normally start when your in command or have your normal environment set up.

/'pathToPython'/python /users/ashsaba/sick-beard/sickbeard.py &

That's all that needs to be in the startSickBeard.sh.  

I have had to do this when running somewhat disgruntled python scripts from CRON at startup as well.  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chipped

ASKER

:)