I wanted to automate the process of changing my ip address using apple-script. So i wrote a script that will automatically do that, But i have problems in setting up the ip address.
set ipAddress to "192.168.110.48"
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.network"
end tell
tell application "System Events"
tell process "System Preferences"
click checkbox "Click the lock to make changes." of window "Network"
tell application "System Events" to keystroke "p"
tell application "System Events" to keystroke "a"
tell application "System Events" to keystroke "s"
tell application "System Events" to keystroke "s"
tell application "System Events" to keystroke "w"
tell application "System Events" to keystroke "o"
tell application "System Events" to keystroke return
click button 11 of window "Network"
tell window "Network"
tell sheet 1
tell tab group 1
click radio button "TCP/IP"
set contents of text field 2 to ipAddress
end tell
end tell
end tell
end tell
end tell
Everything executes fine except for this statement
"set contents of text field 2 to ipAddress"
I am getting the following error:
error "System Events got an error: Can’t set contents of text field 2 of tab group 1 of sheet 1 of window \"Network\" of process \"System Preferences\" to \"192.168.110.48\"." number -10006 from contents of text field 2 of tab group 1 of sheet 1 of window "Network" of process "System Preferences" I checked the UI elements using UIBrowser so i am sure that i am using the correct elements. What is causing the problem? and Also can u tell a better way to write the same thing?