« On the dearth of blog contentShare v1.0 »

[AS] Execute bundled scripts correctly

I’m planning on releasing some Python scripts that I’ve been working on later this week after I get some more testing done. I’m aware that many people are not familiar with Python or the command line so I thought I’d wrap it all up in an applescript application. Script Editor allows me to make script bundles that keep all of the files together. Unfortunately, do shell script does some funky things. I’ve got several versions of Python installed and running do shell script didn’t use the one that I preferred. I couldn’t hard code the path to my preferred Python because many users may have Python installed in a different place (either the default location, or using a package manager like Fink or MacPorts).

In a somewhat fortuitous result, the which command would return the path for my preferred Python installation. Now, in order to make sure that the preferred python is used, I do this in my scripts:

pythonpath = do shell script "which python"
do shell script pythonpath & " " & pathtoscript

So far, this has always used the python installation I expected.

Leave a Reply