i’m having trouble scripting system prefs. an example script:
tell application "System Events"
tell process "System Preferences"
-- set current pane to pane "Network" (this doesn't work)
click pop up button 2 of window "Network"
keystroke "bui"
keystroke return
get value of text field 1 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window 1
end tell
end tell
how do i fix this?
thanks for any help.
Model: iBook G4
AppleScript: v2.1 (80)
Browser: Safari v2.0 (412)
Operating System: Mac OS X (10.4)
this has nothing to do with the above post but i didn’t want to make a new thread. finder gives me the path of a file as folder “URLs” of folder “Scripts” of folder “Library” of startup disk of application “Finder”. how do i get it in the form of MacHD/Library/Scripts/URLs ?
Model: iBook G4
AppleScript: v2.1 (80)
Browser: Safari v2.0 (412)
Operating System: Mac OS X (10.4)
Do you mean how does one call up the required pane? Try telling System Preferences direct:
tell application "System Preferences" to set current pane to pane "com.apple.preference.network"
tell application "System Events" to tell process "System Preferences"
(* continue with script *)
end tell
Whichever we use, we’re targetting a particular application - although the basic role can differ quite significantly. When directly addressing an application, we can access the classes and events included in its AppleScript dictionary - some of which can be extremely powerful. When targetting the process via System Events, we’re mainly tapping into the user interface - to access UI elements such as buttons, check boxes, menu items, etc.
To check out the difference, open (say) the AS dictionary of System Preferences - and then look through the ‘Processes Suite’ of the System Events dictionary.
In general, if an application’s dictionary provides what you need, I’d stick with that. However, an application’s dictionary can sometimes be pretty sparse - and UI scripting is virtually all we have left to accomplish a task…