Calling applescript from objective c code with arguments

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

  1. macrumors newbie

    Joined:
    Feb 18, 2013
    Location:
    India
    #1
    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. macrumors regular

    Joined:
    Aug 21, 2011
    Location:
    Stockholm Sweden
    #2
    One way is to run the script from inside you c using scripting bridge.
    https://developer.apple.com/library...BridgeConcepts/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
     
  3. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #3
    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