PDA

View Full Version : Applescript newbie, is there a way to get it to make my connection inactive/active?




fs454
Oct 5, 2009, 07:54 PM
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



covert panda
Apr 28, 2012, 11:07 AM
i'm also curious to see how this works, it's been bugging me for a while now.

kryten2
Apr 28, 2012, 01:30 PM
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.

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