• 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: Scripting Bridge running method passing an array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Bridge running method passing an array


  • Subject: Re: Scripting Bridge running method passing an array
  • From: has <email@hidden>
  • Date: Fri, 30 Oct 2009 21:35:36 +0000

Kyle Sluder wrote

On Thu, Oct 29, 2009 at 11:54 PM, Scott <email@hidden> wrote:
Thanks for the response Kyle. I will ask Rogue. This is how you send
commands via AS

       tell application "Airfoil"

               -- Connect to Airport Express
               connect to (every speaker whose name is "Computer")

end tell

Ah, this would be a problem∑ your code is trying to pass an NSArray with an NSString in it, whereas the command wants an NSArray containing references to "speaker" objects.

No, the OP's code is passing a *single* reference that identifies *all* of the speaker objects that match the specified condition.


Passing a list of single-item references, as you suggest, would be written like this:

	 tell application "Airfoil"
               connect to (get every speaker whose name is "Computer")
	end tell

That's one application command, 'get', to retrieve a list of references from the application, and a second application command, 'connect to', that takes that list and does something with it. Whether it would actually work is another question: while some apps (e.g. Finder) will happily accept either a multi-item reference or a list of single-item references, most require one or the other and will error if you pass them the wrong one.

Apple events != OOP, despite SB's best attempts to obfuscate them into faux-OO incomprehensibility. It's *RPC + first-class queries* (a rough analogy would be to sending XPath queries over XML-RPC). You will only confuse and frustrate yourself if you try to think about it in OO terms.

As I suggested to the OP when he posted about this on macscripter.net, get a copy of ASTranslate from the appscript website and try running the script through that. Appscript uses far less magical behaviours and syntactic sugar than SB (or AS for that matter), so you should get a somewhat clearer idea of what the above script is actually saying to Airfoil. (Trying to understand Apple event IPC when working in SB is like trying to scuba dive with your swim trunks over your eyes.)

I unreservedly recommend reading Dr William Cook's papers on AppleScript (see the links page of the appscript site); they contain a wealth of insights and information on the subject that you won't find anywhere else. None of the material on Apple's developer site does a remotely competent job of explaining the key concepts behind Apple event IPC and the Apple Event Object Model, IMO, so don't bother looking there.

Regards,

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Scripting Bridge running method passing an array
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Other Linker Flag all_load removes symbols in Instruments?
  • Next by Date: Re: Can't Remove Observer Was: Re: Core Data not fulfill a fault (now: observer) after Save As
  • Previous by thread: Re: Scripting Bridge running method passing an array
  • Next by thread: Re: Scripting Bridge running method passing an array
  • Index(es):
    • Date
    • Thread