Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ElectricMan5

macrumors regular
Original poster
Jul 22, 2008
204
0
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

Moderator emeritus
Jun 15, 2000
7,958
7
This would be a better way to show the Sharing preference:
Code:
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

macrumors regular
Original poster
Jul 22, 2008
204
0
This would be a better way to show the Sharing preference:
Code:
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

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.