I am using NativeProcess to have some applescrit ran in the background. So far what I could achieved is to run applescript like this :
1) Set osascript as the nativeProcess executable
2) supply -e & "tell ..." as arguments
The applescript runs fine.
However, teh script I intend to run can be quite long. So I was more thinking about running osascript with a reference to the applescript file itself. So I put my applescript snippet ithin my src folder and try to pass it as the osascript command argument. It doesn't work not really surprisingly but fact is I don't see how to solve that.
Do I have to copy my embedded applescript file to the local system and then call this specific instance ? Or should I decompose my script as a big array of lines and feed them to the osascript arguments (-e, line 1, -e, line 2 ...?). Second solution seems exhausting.
So what is the way to call my applescript script ? I wish to keep a simple air app and not a bunch of separate files.
Thanks for your help !
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,
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.native Path+"/assets/test.scpt");
nativeProcessStartupInfo.executable = cmdFile
var processArgs:Vector.<String> = new Vector.<String>();
nativeProcessStartupInfo.arguments = processArgs;
nativeProcess = new NativeProcess();
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?