Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to run python script in automator?

I have setup a "run shell script" automator action to run a python script from my applications folder.


The line:


"/usr/bin/python /Applications/MyProg/myPythonProg.py"


does not work. I know its not recognizing the /applications part of the line.


How can I get it to run a program in my Applications folder?


Thanks

iMac, Mac OS X (10.6.8), i5 with Thunderbolt

Posted on Jul 26, 2012 4:25 AM

Reply
Question marked as Best reply

Posted on Jan 12, 2017 6:42 AM

In Automator, you can use the Run Shell Script action, and change the selector from Bash to Python. That is only part of the story, because depending on how your Python script receives its input, will determine which Pass input setting {to stdin, as arguments} that you use to receive passed information.


My standalone Python scripts use this first line if I am deliberately wanting to use something from the default System python (e.g. PyObjC):


#!/usr/bin/python


and the following if I have a different Python version active, where it picks up on the PYTHONPATH environment variable, that is ordinarily unset with the System Python.


#!/usr/bin/env python

7 replies
Question marked as Best reply

Jan 12, 2017 6:42 AM in response to AppleJason

In Automator, you can use the Run Shell Script action, and change the selector from Bash to Python. That is only part of the story, because depending on how your Python script receives its input, will determine which Pass input setting {to stdin, as arguments} that you use to receive passed information.


My standalone Python scripts use this first line if I am deliberately wanting to use something from the default System python (e.g. PyObjC):


#!/usr/bin/python


and the following if I have a different Python version active, where it picks up on the PYTHONPATH environment variable, that is ordinarily unset with the System Python.


#!/usr/bin/env python

Jul 26, 2012 6:11 AM in response to AppleJason

If you type


/usr/bin/python /Applications/MyProg/myPythonProg.py


at the Terminal command line prompt, does it work?


If it works from a Terminal session, then there must be something in your Terminal environment that does not exist when running from Automator. Look at your python script for any environment variables you expect to use and then run add


Run Shell Script

printenv >/tmp/automator.environment.txt


to your Automator script and after running it, use the Terminal to look at /tmp/automator.environment.txt and see if it has the variables you need.


Do you really have the command between "..." in Automator? or did you just do that for your forum posting? If it is inside "..." the sell will not parse it properly.


Can you describe what your script is suppose to do?

Jul 26, 2012 12:19 PM in response to AppleJason

In addition to Bob's question about what it's supposed to do, you should state what it does do.


For example, does it give you an error message? do something unexpected? fail silently?

That will go a long way to helping pinpoint the issue.


Additionally, you say:


I know its not recognizing the /applications part of the line.


How do you know this?


Also realize that as far as the shell is concerned, /Applications is not the same as /applications. Case matters.

How to run python script in automator?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.