Re: Feature request to solve a problematic AppleScript behavior with raw Apple Event codes
Re: Feature request to solve a problematic AppleScript behavior with raw Apple Event codes
- Subject: Re: Feature request to solve a problematic AppleScript behavior with raw Apple Event codes
- From: Matt Neuburg <email@hidden>
- Date: Thu, 21 Oct 2010 18:04:35 -0700
- Thread-topic: Feature request to solve a problematic AppleScript behavior with raw Apple Event codes
>Date: Thu, 21 Oct 2010 21:54:57 +0000
>From: Scott Babcock <email@hidden>
>Subject: Feature request to solve a problematic AppleScript behavior
> with raw Apple Event codes
>
>I ran into a situation in which I needed to branch based on the form of a
>specified object reference (named/index/id). Getting the reference form
>is obscure but relatively easy (coerce the reference to a record and grab
>the <<class form>> property). From there, I need to compare the form to a
>constant (e.g. - <<constant ****name>>).
>
> set procRef to propess "Finder" of application "System Events"
> set refRecord to procRef as record
> if ((<<class form>> of refRecord) is <<constant ****name>>) then
>display dialog "named"
>
>The difficulty in this scenario is that AppleScript is too "helpful".
>When it compiles <<constant ****name>>, this raw code is converted to the
>text "named".
>
>
In Ruby, your script is just
text; merely opening the script or running it doesn't mysteriously cause
its contents to get changed. And inspecting the form of the canonical
reference returned by an application doesn't require any magic tricks.
Here's the rb-appscript equivalent of your script:
procRef = Appscript.app("System Events").processes["Finder"]
ref = procRef.get
if ref.AS_aem_reference.to_s.include? 'by_name("Finder")'
puts "a named reference to the Finder"
end
There's an online book at my Web site that helps you make the jump to
Ruby. m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
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