Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Get preference panel names for UI Scripting System
Apple's GUI Scripting for AppleScript allows you to automate many applications that do not have usable AppleScript dictionaries. For example, you can use GUI Scripting to automate the process of toggling certain settings in System Preferences that do not have keyboard shortcuts (e.g., the "Set Display to Grayscale/Color" option in Universal Access). The way to script System Preferences works is to activate the application and then set the "current pane" to the pane whose settings you want to modify. This is usually done with a snippet like:
tell application "System Preferences"
  activate
  set current pane to pane "com.apple.preference.universalaccess"
end tell
But how do you get the name of the preference pane you want to change? As you can see, the "name" you must use is not the obvious name visible to the user in System Preferences. It is true that you can do without the name if you simply index into the visible window -- but this is not a reliable method (scripts may fail randomly) and your scripts may need to be rewritten if you install new preference panes or if you pass your script to your friends who have a different collection of preference panes than you do. Using the name is much more portable and reliable. Apple does not seem to follow a consistent pattern for the names. The "Accounts" preference pane, for example, is named "com.apple.preferences.users" (note the "preferences" instead of "preference").

In order to get this name that's useful for GUI Scripting, you need to navigate to where the preference pane is actually located (usually in one of /System -> Library -> PreferencePanes, /Library -> PrefereencePanes, or ~/Library -> PreferencePanes), control-click on the .prefPane file and select "Show Package Contents." Then navigate into the "Contents" folder and open up the Info.plist file; there you will find a key called "CFBundleIdentifier" whose value is the name you want.

Once you've managed to get GUI Scripting to select the preference pane you want, the rest of the scripting can be done in the usual way. As an example, here's the full script for toggling gray scale display.


tell application "System Preferences"
  activate
  set current pane to pane "com.apple.preference.universalaccess"
end tell

tell application "System Events"
  if UI elements enabled then
    tell tab group 1 of window 
     "Universal Access" of process "System Preferences"
      click button 4 
       (* may be "Set Display to Grayscale" or "Set Display to Color" *)
    end tell
  else
    tell application "System Preferences"
      activate
      set current pane 
       to pane "com.apple.preference.universalaccess"
      display dialog 
       "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
    end tell
  end if
end tell

delay 2

tell application "System Preferences"
  quit
end tell
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[11,515 views]  

Get preference panel names for UI Scripting | 5 comments | Create New Account
Click here to return to the 'Get preference panel names for UI Scripting' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Apples UI Element Inspector
Authored by: jecwobble on Mar 23, '04 11:34:04AM
This is easier and works with other apps, too.

http://www.apple.com/applescript/uiscripting/02.html

[ Reply to This | # ]

PreFab UI Browser
Authored by: craigz on Mar 23, '04 12:43:17PM

Also PreFab Software's UI Browser is very helpful with GUI Scripting in general. It is not free like Apple's utility, but it is much more powerful. It will also generate code snippets for you which take some of the drudgery out of UI Scripting.

http://www.prefab.com/uibrowser/



[ Reply to This | # ]
Get preference panel names for UI Scripting
Authored by: jakacmar on Mar 23, '04 03:06:56PM
I've run into this a few times myself in trying to help others on the Apple Discussion boards script System Prefs. When I need the name of a pane, I just get it from AppleScript. Open System Prefs, seelct the pane you want and run

tell application "System Preferences"
set thePane to the name of the current pane
display dialog thePane
end tell
I've found that some panes use "com.apple.preferences.xxxx" while others use "com.apple.preference.xxxx". Note the missing "s" in preference(s). Not sure why the discrepancy. Just another method to do the same.

[ Reply to This | # ]
Get preference panel names for UI Scripting
Authored by: SimonDorfman.com on Mar 23, '04 06:10:59PM
nice. i added copy to clipboard...

--open system preferences to desired panel, then run script to find out name.
tell application "System Preferences"
	set thePane to the name of the current pane
	set the clipboard to thePane
	display dialog thePane & return & return & "This has been copied to the clipboard."
end tell


[ Reply to This | # ]
Get preference panel names for UI Scripting
Authored by: ranker on Mar 24, '04 11:33:03AM
To get a list of all the preference panes do this:
tell application "System Preferences"
	name of panes
end tell


[ Reply to This | # ]