1 person found this helpful
I would advice to search the web for AppleScript discussions. When script is run (it is invoked with "on run") it could take numbered (finited) list of arguments or blanket, arrray like object of arguments in the way described below:
on run args set firstname to item 1 of args as string set lastname to item 2 of args as string return "Hello " & firstname & space & lastname end run
that could be executed from terminal (using osascript as you already done):
osascript MyScriplet.scpt Peter Blazejewicz
which is expected to display (and actuall does):
Hello Peter Blazejewicz
This is a way you could pass arguments in post 10.4.* OS X command line. You would have to incorporate "if then" conditions and "as string", "as boolean" AppleScript sugars in your script to check number of arguments and to use only passed ones and to convert them into required data type in AppleScript,
Your response is really helpful. I finally got the applescript file to be ran but passing arguments was a concern to which you answered.
Thanks a lot
How are you using the osascript process? Can you post some code?
Sorry for the delay. Technical issues with my yahoo mail :
Here is the code :
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var cmdFile:File = File.documentsDirectory.resolvePath("/usr/bin/osascript");
var scriptFile:File =File.documentsDirectory.resolvePath(File.applicationDirectory.nativePath+"/assets/test.scpt");
nativeProcessStartupInfo.executable = cmdFile
var processArgs:Vector.<String> = new Vector.<String>();
nativeProcessStartupInfo.arguments = processArgs;
nativeProcess = new NativeProcess();
Great! Thank you Loic
Hi, presently I'm also put into this learning loop of communication between AIR and AppeScript. I yet not figured out how can I pass a command line argument to the AppleScipt (considering the AppleScript triggers Terminal app and run the command thrown by Flex as an argument). Did you through such scenario also? Can you help please?
Thanks for this code. I have similar code that that I want to launch an Applescript via osascript. I have a button that essentially starts the native process objects after I setup its StartupInfo object. I have the executable set to an air File object type, and the nativePath property logs as "/usr/bin/osascript"
The problem is that nothing happens when I click the button--I mean I know the event handler is being called because I have a simple log statement in there. But there are no errors that come up--it's silent. How might I be able to investigate what is going on with the Native Process after the .start(StartupInfo) method is called. Are there any listeners I can use?