PDA

View Full Version : Applescript click window button help!




ElectricMan5
Mar 16, 2009, 11:28 AM
I'm using this script:

tell application "System Preferences" to activate

tell application "System Events"
tell process "System Preferences"
click button "Network" of window "System Preferences"
delay 1
end tell
end tell


It compiles well, but it doesn't run!

It comes up with the error:

System Events got an error: Canít get button "Network" of window "System Preferences" of process "System Preferences".


I want the script to automate opening up system preferences, then opening up sharing, then turning "web sharing" on and off.

Please help! Thanks.



kainjow
Mar 16, 2009, 12:56 PM
This would be a better way to show the Sharing preference:
tell application "System Preferences"
set current pane to pane id "com.apple.preferences.sharing"
end tell
Then after that you can use UI scripting.

ElectricMan5
Mar 16, 2009, 01:00 PM
This would be a better way to show the Sharing preference:
tell application "System Preferences"
set current pane to pane id "com.apple.preferences.sharing"
end tell
Then after that you can use UI scripting.

Thanks! What is UI Scripting, though?

kainjow
Mar 16, 2009, 01:21 PM
It's accessing the controls (buttons, text fields, etc) of a program via AppleScript, which is what the "click" command is. You would only use it when there isn't a built-in way of doing what you want through AppleScript. Perfect example is above where System Preferences already supports showing a certain preference pane, but you were wanting to manually click the button instead.