I have a simple Applescript I have written to try to update the DNS Servers in Network Preferences.
Right now the pane is set to the Network Preferences, I just need to select Built in Ethernet and then make Changes to the DNS Servers.
Anyone got any ideas of the best way to do this (other than manually entering them)?
Thanks,
Jeff
tell application “System Preferences”
activate
set current pane to pane “com.apple.preference.network”
display dialog “Please set your DNS Servers to 160.111.8.10 and 160.111.8.18”
but never got an answer. i finally did as you are and displayed a dialog asking the user to do this. here is a link to my script for setting up a caching DNS server:
Someone was asking about this the other week, they where looking down the GUI route, i did a search but didn’t come up with much other than a small bit.
so i’ve added a bit more to it an have come up with this, GUI scripting isn’t the best and always depends on a few factors one being that i tested it on my mac
so yours should have the same menus etc… it might mean adding an extra tab here or a delay there but this works on my machine, with the LOCK unclicked in system prefs:
tell application "System Preferences"
activate
set current pane to pane "Network"
end tell
tell application "System Events"
tell process "System Preferences"
set frontmost to true
tell window 1
click pop up button 2
tell pop up button 2
tell menu 1
click menu item "Built-in Ethernet"
repeat 5 times
keystroke tab
end repeat
keystroke "160.111.8"
keystroke return
keystroke "160.111.8.18"
end tell
end tell
end tell
end tell
end tell
Although I haven’t figured out how to do anything with it, I did find my DNS address in /Library/Preferences/SystemConfiguration.plist buried under a key called ServerAddresses. I don’t know whether changing that will alter the setting on the System Preferences pane, however - those are often loaded at login time so you’d probably have to logout/login to see the change.
That error just means that its trying to click on something but can’t cause it’s not in the same place probably has it is in mine.
i’m on 10.4.8 not sure that would make a difference…
try and break the script down a line at a time to see where it finds the error it might just mean adding another tab or removing it or something like that…
I still was having problems with the tabs not being selected after built-in ethernet was selected… I found a utility called UI browser, so I tried adding some extra code to tell the tab groups and groups to see if I could enter the DNS servers and search domains…
Still not working though.
tell application “System Preferences”
activate
set current pane to pane “Network”
end tell
tell application “System Events”
tell process “System Preferences”
set frontmost to true
tell window “Network”
click pop up button 2
tell pop up button 2
tell menu 1
click menu item “Built-in Ethernet”
tell group 1
tell tab group 1
tell group 1
set value of text field 1 to “160.111.8.10”
set value of text field 2 to “domain.com”
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
If you need to change the dns servers in network preferences i found using a do shell script
do shell script “networksetup -setdnsservers Ethernet 192.168.0.1” with administrator privileges
just change the ip to the address of your dns server.
to change domain search use networksetup -setsearchdomains Ethernet domain1 domain 2
use the man networksetup in terminal to get more info…