Skip navigation
Currently Being Moderated

Run applescripts from AIR

Sep 23, 2011 1:21 AM

Hi all,

 

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 !

 

Loic

 
Replies
  • Currently Being Moderated
    Sep 23, 2011 3:54 AM   in reply to Loic_aigon

    Hi,

     

    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,

     

    hth,

    regards,

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2012 6:56 PM   in reply to Loic_aigon

    How are you using the osascript process? Can you post some code?    

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2012 1:43 PM   in reply to Loic_aigon

    Great! Thank you Loic

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 17, 2012 11:06 PM   in reply to Loic_aigon

    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?

     

     

    Thank you.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points