Set IP Address

Hi,

I would like to set the AirPort IP address via AppleScript. See below what I’ve tried until yet.


activate application "System Preferences"
tell application "System Events"
  tell process "System Preferences"
    tell window "System Preferences"
      click button "Network"
    end tell
  end tell
  tell window "Network"
    tell group 1
      click button "Configure..." <-- Here's the error (NSReceiver... (4))
    end tell
  end tell
end tell

The strange behavior is, that when I execute the following lines with System Preferences started it works fine…


activate application "System Preferences"
tell application "System Events"
  tell process "System Preferences"
    tell window "Network"
      tell group 1
        click button "Configure..." <-- Now it works fine... :-/
    end tell
  end tell
end tell

So could anybody tell me what I’m doing wrong??

Thanks.

Model: Mac mini 1.83Ghz, 1GB RAM
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)

in your first example there is no UI element button “Network” of window “System Preferences”

to address a specific preference pane, you can use this code

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		click button 1 of group 1 of window 1
	end tell
end tell

Thank you very very much… :slight_smile:

Here’s what worked for me…


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window "Network"
			tell group 1
				tell button 1
					click
				end tell
				tell tab group 1
					tell radio button 2
						click
					end tell
					tell group 1
						tell group 1
							tell group 1
								tell text field 1
									set value to "192.168.0.12"
								end tell
								tell text field 3
									set value to "192.168.0.1"
								end tell
							end tell
						end tell
						tell text field 1
							set value to "192.168.0.1"
						end tell
					end tell
				end tell
			end tell
			keystroke "q" using command down
			tell sheet 1
				tell button "Apply"
					click
				end tell
			end tell
		end tell
	end tell
end tell

Regards

Stefan

PS: Cool… We’ve the same name… :smiley:

Model: Mac mini 1.83Ghz, 1GB RAM
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)

… und sprechen die gleiche Sprache :wink:

without the millions of tell blocks it looks much clearer:

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window "Network"
			tell group 1
				click button 1
				click radio button 2 of tab group 1
				set value of text field 1 of group 1 of group 1 of group 1 of tab group 1 to "192.168.0.12"
				set value of text field 3 of group 1 of group 1 of group 1 of tab group 1 to "192.168.0.1"
				set value of text field 1 of group 1 of tab group 1 to "192.168.0.1"
			end tell
			keystroke "q" using command down
			click button "Apply" of sheet 1
		end tell
	end tell
end tell