Recently I was trying to schedule a Python script to run on my Mac. The script basically creates separate config files that my backup script scrolls through and then backs them up to my Dropbox.
Currently I backup my Automator apps, Automator workflows, saved searches etc. I dynamically create the configuration files so when I add new ones, I don't need to edit anything it will just run.
I knew my Python script ran OK from the Terminal as I have been running this for a while, I just call the script and the arguments and everything was good.
I wanted to set this up in Automator as I want it scheduled, and I was going to schedule the Application to run via iCal.
When I setup the command in Automator, it would not run. In automator I had selected Run Shell script, I had selected /bin/bash (default) as my shell, changed Pass Input to As arguments then added the lines
python /path_to_script/create_conf_files.py -sas
python /path_to_script/create_conf_files.py -services
The action would just error out, there is some checking for arguments in the script, so I left them out and the program would run, this was starting to annoy me, but after a little Google-Fu I saw an post about environment variables in a python script not being picked up. I have certain variables set on all machines I use, Windows, Solaris, Linux and Mac, so when I run my scripts they don't need editing they just pick up the variables. I know they are set in my profile etc and it runs on the Mac. So the reason the code would run is because no variables are being used in the start of the script, the error checking etc.
To test if automator was getting my environment settings, I wrote a very simple action, which you can see below
When I checked the output file, I could see they were not being picked up, so a quick simple fix was to add them to the top of the action, before I call the scripts.
python $scripts/python/create_conf_files.py -sas
python $scripts/python/create_conf_files.py -services
Once I had these set the Automator Application would work perfectly, now come the challenge of setting this to run Automatically via iCal.
I am always interested in your thoughts so if you have any comments or feedback then please feel free to add any comments, or you can mail me here.