Skip navigation

How to run python script in automator?

4196 Views 5 Replies Latest reply: Aug 30, 2013 12:32 PM by Camelot RSS
AppleJason Level 1 Level 1 (10 points)
Currently Being Moderated
Jul 26, 2012 4:25 AM

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
  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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?

  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    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.

  • mattyod Calculating status...
    Currently Being Moderated
    Aug 29, 2013 1:11 PM (in response to AppleJason)

    You have a whitespace character in your path, "/usr/bin/python /Applications/MyProg/myPythonProg.py".

  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Aug 30, 2013 12:32 PM (in response to AppleJason)

    So the upshot is that you weren't calling it properly. You need to add the -d switch (presumably to deamonize the process so that it continues to run once the calling process (your Automator action) has finished.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.