Calling applescript from objective c code with arguments

Discussion in 'Mac Programming' started by Jitin Jindal, Mar 3, 2013.

  1. Jitin Jindal macrumors newbie

    Feb 18, 2013
    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.
  2. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    One way is to run the script from inside you c using scripting bridge.

    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.

    // gunnar
  3. Red Menace macrumors 6502

    Red Menace

    May 29, 2011
    Littleton, Colorado, USA
    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.

Share This Page