PDA

View Full Version : Calling applescript from objective c code with arguments




Jitin Jindal
Mar 4, 2013, 12:14 AM
hello Friends

I have some applescript which are helping me in solving some issues i want to call these applscript through objective c code with input arguments for script.

will you please help me how can i call these scripts from objective c code?

NOTE: I also want to pass input arguments for the script.



ghellquist
Mar 4, 2013, 05:25 AM
One way is to run the script from inside you c using scripting bridge.
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html

Another way is to create a text string and then "system" it (note, I probably have the quotes a bit wrong here).
system("osascript -e \'tell app \"Address Book\" to get the name of every person\' | perl -pe \'s/, /\n/g\' | sort | uniq -d");

A third way is use NSTASK. You could check eg this page for a start on NSTASK.
http://stackoverflow.com/questions/8705381/cocoa-objective-c-shell-script-from-application


// gunnar

Red Menace
Mar 4, 2013, 11:03 AM
Assuming you are running at least Snow Leopard, a fourth way would be to add an AppleScriptObjC class to your project and call the desired handlers/methods from the Objective-C code.