Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing a unique reference




On 28 Jul 2006, at 16:45, Daniel Jalkut wrote:

... the hiccup I'm running into is that System Events seems to favor "named references" ... almost pathologically so. So when I've got 4 processes all named "DashboardClient," I have to be careful in formulating my references to them that I don't end up with a reference by name, because *although it provided the reference*, it's not capable of uniquely resolving it.

The workaround I've come up with is to use a reference to a whose specifier...

That's an interesting one, Daniel.

I suppose one could also specify the required target individually (first application process whose...) rather than a single-item list (application processes whose...). However, the behaviour is similar in either case, since a reference to the specification is still essential for accurate, subsequent identification. Without it, confusion (caused, as you say, by dashboard clients sharing the same name) reigns:

----------------
tell application "System Events"
	set myWidget to (first application process whose title is "Weather")
	title of myWidget
end tell
--> "Sudoku.wdgt"
----------------

The cause is confirmed by the event log:

----------------
tell application "System Events"
	get application process 1 whose title = "Weather"
		application process "DashboardClient"
	get title of application process "DashboardClient"
		"Sudoku.wdgt"
end tell
----------------

A tell statement, by avoiding the evaluation resulting from the set command, could also help to keep a reference intact:

----------------
tell application "System Events" to tell UI element 1 of scroll area 1 of ¬
window 1 of (first application process whose title is "Weather")
if not (exists) then return beep (* Dashboard needs to have been shown once *)
set loc to value of static text 1 of (second group where class of UI elements contains static text)
set tmp to value of static text 1 of groups of (first group where class of UI elements contains group)
end tell
set {intl, msg} to {ASCII number loc's character 1, {}}
if intl > 96 and intl < 123 and (count loc) > 1 then set loc to (ASCII character (intl - 32)) & loc's text 2 thru end
repeat with i from 1 to 6
tell tmp to set msg's end to tab & tab & item i & tab & tab & item (6 + i) & tab & tab & item (12 + i)
end repeat
set {tid, text item delimiters} to {text item delimiters, return & return}
set {msg, text item delimiters} to {msg as Unicode text, tid}
display alert "Temperature Forecasts for " & loc & ":" & return & return & ¬
tab & tab & "Day" & tab & tab & "High" & tab & "Low" message msg
----------------


---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >Forcing a unique reference (From: Daniel Jalkut <email@hidden>)
 >Re: Forcing a unique reference (From: Andrei Tchijov <email@hidden>)
 >Re: Forcing a unique reference (From: Daniel Jalkut <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.