Useful Applescript for Mac OS X users
Mac users usually hate mucking about on a command line. I certainly don't like it. Personally, I think the Terminal application should have been an optional install (perhaps with the Developer Tools). But I digress...
Driven by this dislike, I developed an Applescript wrapper for programs that only come as command lines. For example, python scripts. I enclose a sample Applescript to demonstrate how to do it.
This Applescript runs python scripts. It demonstrates how to set up a persistent variable that can store the path to the python script to be run, so no changes need to be made to the Applescript to run different python scripts. The Applescript only ever prompts for a new python script when it cannot locate the old one.
It also shows how a persistent variable can be used to store a user-specific value, which can later be passed to the python script or used elsewhere. Again, eliminating the need to manually edit the Applescript. As written, the persistent value is prompted for when first run, or when run on its own by double-clicking the icon. If it's already been supplied, it's not prompted for when the Applescript is run by drag&drop of files and/or folders onto the icon.
Speaking of drag&drop, this Applescript also shows how to process files and folders dropped onto the Applescript, so that each file (of a particular type or types) can be passed individually to the chosen script, and how to manipulate the file names to generate an output file name based on the input file names.
Some users may find it useful in its current form, but only if they have a suitable python script already, as the attached file contains no python scripts itself. Currently, the Applescript calls the chosen python script with a command line like
python [pythonscript] [infile] [outfile] [persistent value]
Obviously, this would need to be changed if your target python script takes different parameters. I find it very useful as-is.
I hope others find it educational and useful.
Last edited by pdurrant; 02-09-2010 at 06:11 AM.
|