• 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: Backlight using GUI scripting doesn't work...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Backlight using GUI scripting doesn't work...


  • Subject: Re: Backlight using GUI scripting doesn't work...
  • From: kai <email@hidden>
  • Date: Mon, 9 Oct 2006 04:55:43 +0100


On 9 Oct 2006, at 00:44, Bill Cheeseman wrote:

on 2006-10-08 7:29 PM, kai at email@hidden wrote:

The first line of the script reveals not only the relevant pane, but
also the required tab (anchor). Since execution won't proceed until
the anchor is revealed, this method not only reduces the clicks
required in the UI; it also avoids some of the timing issues that
might arise, following a click, while waiting for the target element
to appear.

This is very cool stuff, kai. Can you elaborate on the 'anchor' element?
I've never understood what it is, and I don't have any more time left to
explore it.

I believe the term "anchor" is used in various situations, Bill. In this context, it's an element of a pane within a System Preferences window. It has only one (read only) property: name. This is used to identify it when using the 'reveal' command. The 'anchor' element and the 'reveal' command are both referred to in System Preferences' AS dictionary.


Some panes (e.g. "com.apple.preference.general", "com.apple.preference.digihub.discs", "com.apple.preference.expose", "com.apple.preference.dock", "com.apple.preference.security", "com.apple.preference.startupdisk") might have only a single anchor - usually named "main". So something like...

----------------
tell application "System Preferences" to reveal anchor "main" of pane id "com.apple.preference.general"
----------------


... will have pretty much the same effect as:

----------------
tell application "System Preferences" to set current pane to pane id "com.apple.preference.general"
----------------


Other panes might include a "main" anchor along with several others. OMM, for example, pane id "com.apple.preference.sound" contains 4 anchors: "main", "output", "input" and "effects". Revealing the "main" anchor will simply show the sound pane that was chosen previously. (This could be used if access to only the output volume slider was required - since that's generally available in all variants of the sound pane.) Revealing the "output", "input" and "effects" anchors will access the 'balance', 'input level' and 'alert' volume sliders, respectively.

In many cases, revealing an anchor can perform the equivalent function of selecting a tab. However, that's not always the case. The following, for instance, effectively emulates the clicking of the "Hot Corners..." button of "Desktop & Screen Saver". So it will display the "Active Screen Corners" sheet.

----------------
tell application "System Preferences" to reveal anchor "ScreenSaverPref_HotCorners" of pane id "com.apple.preference.desktopscreeneffect"
----------------


In other situations, revealing an anchor is about the only way to access certain elements. Anyone who has ever tried, via GUI scripting, to get into Accounts/Login Options will know what a headache it can be. But something like this (with appropriate password precautions) should do it:

----------------
to authenticate_changes()
	tell application "System Events" to tell window ¬
		"Authenticate" of process "SecurityAgent"
		tell group 1
			(* modify following name/password *)
			set value of text field 1 to "some name"
			set value of text field 2 to "some password"
		end tell
		click button "OK" of group 2
	end tell
end authenticate_changes

tell application "System Preferences" to set current pane to ¬
	pane id "com.apple.preferences.users"

tell application "System Events" to tell window 1 of ¬
	process "System Preferences" to tell button ¬
	"Click the lock to make changes." to if exists then
	click
	my authenticate_changes()
end if

tell application "System Preferences" to reveal anchor ¬
	"loginOptionsPref" of pane id "com.apple.preferences.users"
----------------

For anyone wishing to explore this kind of thing further, but who may be unsure how to get a pane id or anchor name, the following routine should produce a list:

----------------
set text item delimiters to return & tab
tell application "System Preferences"
	set l to id of panes
	repeat with i in l
		set i's contents to i & {"", ""} & ¬
			name of anchors of pane id i
	end repeat
end tell
set text item delimiters to return & return
set l to return & l & return
set text item delimiters to {""}
tell application "TextEdit"
	launch
	activate
	make document with properties {text:l}
end tell
----------------

Hope that helps as a brief intro...

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Backlight using GUI scripting doesn't work... (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Backlight using GUI scripting doesn't work...
  • Next by Date: RE: Creating an environment variable from AppleScript
  • Previous by thread: Re: Backlight using GUI scripting doesn't work...
  • Next by thread: Re: Backlight using GUI scripting doesn't work...
  • Index(es):
    • Date
    • Thread