title: Applescript setting ip address
body: <p>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.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Everything executes fine except for this statement </p>
  
  <blockquote>
    <p>"set contents of text field 2 to
    ipAddress"</p>
  </blockquote>
  
  <p>I am getting the following error:</p>
  
  <blockquote>
    <p>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?</p>
  </blockquote>