views:

216

answers:

2

I have installed Py-Appscript on my machine and it can be used with the Python installation at /Library/Frameworks/Python.framework/Versions/Current/bin/python.

I am trying to use this installation of Py-Appscript with an Automator service. To do this, I use the Run Shell Script action and then set the Shell to usr/bin/python (which is my only choice for Python, unfortunately).

The usr/bin/python does not appear to have access to my third-party modules and crashes on the line:

from appscript import *

Is there a way for me to give usr/bin/python access to my third-party modules? OR Is there a way to tell Automator to use /Library/Frameworks/Python.framework/Versions/Current/bin/python instead?

I need Automator to run the Python directly from the Run Shell Script action. Any action that calls Python scripts that are external to Automator (via bin/bash, for example) does not perform quickly enough to be useful.

A: 

When you install modules, you typically install them per Python instance. So in this case you have installed them for the Python in /Library/Frameworks/Python.framework/Versions/Current/bin/python, and it will then be available only for that Python. /usr/bin/python is then apparently another Python installation (I'm not an OS X expert).

To make it available for the /usr/bin/python installation, install it for /usr/bin/python.

Lennart Regebro
Thanks for the advice. Unfortunately, I installed appscript using `sudo easy_install appscript` in Terminal and I have no idea how to redirect it to install for `/usr/bin/python`.
Chris Redford
Okay, I was able to attempt to install appscript for `/usr/bin/python` using:`sudo /usr/bin/python -m easy_install appscript`However, this encountered the error:`unable to execute gcc-4.2: No such file or directory`Leaving me back at square one, unfortunately. Given this, it looks like my best bet is somehow getting Automator to use `/Library/Frameworks/Python.framework/Versions/Current/bin/python`
Chris Redford
@credford: gcc is part of Xcode. Try installing that first.
Ignacio Vazquez-Abrams
I actually have Xcode installed already. I'm an iPhone developer.
Chris Redford
Normal command is `sudo /usr/bin/easy_install appscript`, but yours should work as well. Perhaps something's wonky with your shell profile or you've changed something in your system? The built-in Python requires gcc-4.2 to build extensions, which comes with Xcode3.2. If you've installed an older Xcode or have changed your gcc setup then that might be the reason it can't find [presumably] gcc-4.2.
has
+1  A: 

Okay, I was able to get it working using a hack found at How do I execute a PHP shell script as an Automator action on Mac OS X.

Inside of the Run Shell Script action, I used the /bin/sh/ shell with <<EOF ... EOF to the proper Python installation.

So for example, entering

/Library/Frameworks/Python.framework/Versions/Current/bin/python <<EOF
from appscript import *
Numbers = app('Numbers')
EOF

Into the code section of the Run Shell Script action will work. So one can call the proper installation (/Library/Frameworks/Python.framework/Versions/Current/bin/python above) and put their program between the <<EOF ... EOF delimeters.

Chris Redford
If you're going to do that then you should just specify that Python executable in the script's shebang line and chmod the script executable.
Ignacio Vazquez-Abrams
I actually tried that already and it ran slower than the above method. I assume the reason is because both methods need to access the `Python.framework` installation from the hard drive but the above method at least doesn't have to access the code from a different hard drive location than the Automator action. So I am thinking the above method requires 2 hard drive retrievals (python and Automator) while the method you are suggesting requires 3 (python, executable .py file, and Automator).
Chris Redford