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

Discussion in 'Mac Programming' started by fs454, Oct 5, 2009.

  1. fs454 macrumors 68000

    Dec 7, 2007
    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,

    :edit: also, I'm using Snow Leopard 10.6.1
  2. covert panda macrumors newbie

    Apr 28, 2012
    same problem here

    i'm also curious to see how this works, it's been bugging me for a while now.
  3. kryten2, Apr 28, 2012
    Last edited: Apr 28, 2012

    kryten2 macrumors 6502a

    Mar 17, 2012
    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.

    tell application "System Preferences"
    	--	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
    end tell

    Attached Files:

Share This Page