Set DomainSearch & Dns Servers in Network pref pane

Hi,

I’ve read several posts here about my problem, yet i can’t make my script works.
Here it is :

set DNSServers to "10.10.10.10, 10.10.10.11"
set SearchDomain to "toto.com, titi.com"
 
tell application "System Events"
 if (name of processes) contains "System Preferences" then tell application "System Preferences" to quit
end tell
delay 1
tell application "System Preferences"
 activate
 set current pane to pane "com.apple.preference.network"
end tell
 
tell application "System Events" to tell process "System Preferences"
 set frontmost to true
 click pop up button 2 of window 1
 click menu item "Ethernet intégré 1" of menu 1 of pop up button 2 of window 1
end tell
delay 1
 
tell application "System Events" to tell process "System Preferences"
 tell tab group 1 of group 2
  delay 1
  set value of text field 1 of group 1 to DNSServers
  set value of text field 2 of group 1 to SearchDomain
 end tell
end tell
 
tell application "System Preferences" to quit

It seems like i can’t select the tab (TCP/IP, Proxies, Appletalk, etc) thus not filling in my text in text field
I tried a click radio button “TCP/IP” but it doesnt work.

Any help will be appreciated.

Thanks.

ps: im on 10.4.8 ppc. Script editor 2.1.1 & applescript 1.10.7

Ok i fixed the tab thing. Still im not able to fill the text field :

set DNSServers to "10.10.10.10, 10.10.10.11"
set SearchDomain to "toto.com, titi.com"

tell application "System Events"
	if (name of processes) contains "System Preferences" then tell application "System Preferences" to quit
end tell
delay 1
tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell

tell application "System Events" to tell process "System Preferences"
	set frontmost to true
	click pop up button 2 of window 1
	click menu item "Ethernet intégré 1" of menu 1 of pop up button 2 of window 1
end tell
delay 1

tell application "System Events" to tell process "System Preferences"
	click radio button "TCP/IP" of tab group 1 of group 1 of window 1
        delay 1
	set value of text field 1 of tab group 1 of group 1 of window 1 to DNSServers
	set value of text field 2 of tab group 1 of group 1 of window 1 to SearchDomain
end tell

tell application "System Preferences" to quit


If it is in 10.4 you are working, I might be able to give some assistance. I’ve just written a small script to make a new location in the Network PrepPane. Here’s how I’ve done it (adapted to your code)


set DNSServers to ("10.10.10.10" & (ASCII character 13) & "10.10.10.11") as string
set SearchDomain to "toto.com, titi.com"

tell application "System Preferences"
	activate
	set current pane to pane "Network"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Network"
	tell pop up button 2
		click
		click menu item "Ethernet intégré 1" of menu 1
	end tell
	delay 1
	click radio button 1 of tab group 1 of group 1
	set value of text field 1 of group 1 of tab group 1 of group 1 to DNSServers
	set value of text field 2 of group 1 of tab group 1 of group 1 to SearchDomain
	delay 1
	click button "Apply Now"
end tell

tell application "System Preferences" to quit

that script seems to be working for me. I hope it can help you too

Greetz

You can quickly find what dns server settings are with this:


set DNS to paragraphs of (do shell script "cat /etc/resolv.conf")
repeat with P in DNS
	set contents of P to (words 2 thru -1 of P) as text
end repeat
DNS

These can also be set using scutil; see its man page, I haven’t done it myself. To use it to get the parameters:

set s to do shell script "scutil --dns"

very cool :cool: