Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fs454

macrumors 68000
Original poster
Dec 7, 2007
1,977
1,823
Los Angeles / Boston
Alright, so I have my Mac Pro and Macbook Pro here at college, and a company called Apogee provides internet service. Problem is, whenever I switch computers, it requires me to re-authenticate with Apogee using my username/password. This is saved so all I have to do is click through, but after authenticating, it requires that you RESTART your computer before the connection works.

This is very, very annoying, so I've figured that simply going into System Preferences, clicking "Ethernet 2" (or whatever you're using to connect), making it inactive, hitting apply, then making it active again and hitting apply again gets it on the move without a restart.

The question is: How do I get this to happen in Applescript? I'm extremely unfamiliar with the workings of it, but so far I love how simple the commands are. Unfortunately the task I'm trying to do is a little over my head for a first time script. Some googling has gotten me this far:

tell application "System Preferences" to reveal anchor "Ethernet" of pane "Network"

Which opens the correct ethernet anchor on the left panel. But, how does it know which one I want? I have Ethernet 1 and Ethernet 2 in that panel, this code seems to always go to what I want it to, but how does it know if the command is simply "Ethernet"?

More importantly, what do I do next? Sorry for being a braindead newbie at this, but I'm really not sure how to progress. I need it to click the "gear" button at the bottom of the pane, click "make service inactive," then "apply", then the same gear menu again, "make service active," then "apply" once more, and then quit System Prefs.


Is this possible? Thanks a ton for your time,
fs454

:edit: also, I'm using Snow Leopard 10.6.1
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Get you started

Oops, I didn't see the first post was from 2009. Added delays because the script rushed through the statements and would trip. The script is tested and fully functional. By default the first service is selected eg Ethernet.

Code:
tell application "System Preferences"
	activate
	--	reveal anchor "Ethernet" of pane "Network"
	tell application "System Events"
		tell process "System Preferences"
			-- insert GUI Scripting statements here
			click button "Network" of scroll area 1 of window "System Preferences"
			delay 1
			-- If the 5th Service(Skynet) is needed 
			--select row 5 of table "Services" of scroll area 1 of window "Network"
			--delay 1
			click menu button "Service Actions" of window "Network"
			delay 1
			click menu item "Make Service Inactive" of menu 1 of menu button "Service Actions" of window "Network"
			delay 1
			click button "Apply" of window "Network"
			delay 2
			click menu button "Service Actions" of window "Network"
			delay 2
			click menu item "Make Service Active" of menu 1 of menu button "Service Actions" of window "Network"
			delay 2
			click button "Apply" of window "Network"
			delay 8
		end tell
	end tell
	quit
end tell
 

Attachments

  • Picture 4.png
    Picture 4.png
    19.4 KB · Views: 182
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.