Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Pass command-line arguments to AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Pass command-line arguments to AppleScript
Authored by: mzs on Jun 10, '05 01:36:44PM
Here is a trick I learned from the ORA AppleScript book to pass args into a compiled AppleScript that works with all versions of OS X.

In a Bourne style shell do this (in csh style shells do a setenv):


my_foo=val osascript foo.scpt 

Now at the beginning of the AppleScript add this:


set this_foo to system attribute "my_foo"

The "system attribute" corresponds to the environment variables, so what you are doing is passing an argument as an environment variable. You can now use this_foo in your script to get your passed value. In practice the overhead involved with accessing a separate AppleScript file and using the system extension to extract the value of the environment variable takes more time than compiling a SHORT AppleScript so keep this in mind. You will only see a speed increase for your longer AppleScripts, the ones that take a longer time to compile.

[ Reply to This | # ]

10.4: Pass command-line arguments to AppleScript
Authored by: John Rethorst on Jul 29, '05 09:02:13PM

Can the Terminal script ("% osascript a.scpt world") be saved as an application, so double-clicking it will run it?



[ Reply to This | # ]