• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Should Cocoa apps pass parameters to AppleScript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should Cocoa apps pass parameters to AppleScript?


  • Subject: Re: Should Cocoa apps pass parameters to AppleScript?
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 14 Jan 2008 09:37:24 -0800

On Jan 13, 2008, at 5:55 PM, Devraj Mukherjee wrote:

I have a design question. My humble Cocoa application runs bits and pieces of AppleScript to interact with various standard applications. It would be nice to send the AppleScript some parameters that it can use out of my application to feed into the other apps it interacts with.

Now should I consider passing parameters to the AppleScript or should I run the AppleScript from with the Cocoa app, the AppleScript in turn queries my application (so assuming that my Cocoa app responds to the AppleScript calls) and fetch vars out like that?

There are a few different ways to approach the problem:

1. Pass parameters to the script. You'll need to use OSAExecuteEvent to do this, but what the function interface in the script looks like is up to you. You can use the "run" handler, define your own terminology-based handler a la Folder Actions, or use a user-defined handler -- see QA1111 for an example.

2. Use a script template. That is, the "script" in your application is a string constant with some replacement bits ("%@") in it; to execute the script, use +stringWithFormat: to fill everything in, then compile and execute.

3. Make your application scriptable. (Ideally, you ought to be doing this anyway.) Because the script runs in the context of your application, it can easily ask for the necessary bits of information. Adding scriptable bits *purely* for the benefit of a script handler is probably not a good idea, though.

4. Don't use AppleScript. Really, NSAppleScript should be reserved for running user-supplied scripts -- in other words, you don't know at build time what the scripts are going to be. If the logic is static, then you ought to be sending Apple events directly from Cocoa. In theory, you can use NSAppleEventDescriptor and AESend to do this, but it's pretty painful, so we suggest using a higher-level framework. appscript is a third-party framework which works from Panther on; Scripting Bridge is Apple-supplied and works from Leopard on.



--Chris Nebel
AppleScript Engineering

P.S.: This sort of question is probably better directed to email@hidden , but since a lot of the Implementors folks also read Users, don't sweat it too much.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden
References: 
 >Should Cocoa apps pass parameters to AppleScript? (From: "Devraj Mukherjee" <email@hidden>)

  • Prev by Date: Re: Leopard(?) strikes again
  • Next by Date: Re: Is this the correct list to ask for Leopard Scripting Bridge questions?
  • Previous by thread: Re: Should Cocoa apps pass parameters to AppleScript?
  • Next by thread: Leopard(?) strikes again
  • Index(es):
    • Date
    • Thread