how to control airport with automator

Discussion in 'macOS' started by marvin*1*2, Oct 19, 2009.

  1. marvin*1*2 macrumors member

    marvin*1*2

    Joined:
    Jun 19, 2007
    Location:
    Yrp!
    #1
    hi
    i'd like an automator thingy to do the following for me:
    1. activate airport
    2. wait a lil and then login to my vpn account (defined in apple's vpn)

    ideally, also doing the reverse (logout vpn, deactivate airport).

    now, automator's record function already fails as the mouse pointer never hits the airport icon when playing back my recording....:confused:

    anybody know what's wrong and how to do this properly?
    thank you.
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    I would personally do the following:

    Set up a new location: Airport-VPN or something like that. Set it up with the right connections and use the following AppleScript.

    Code:
    
    -- Change Network Location
    do shell script "/usr/sbin/scselect Airport-VPN"
    
    -- Wait 20 seconds
    delay 20
    
    -- Connect to VPN
    tell application "System Events"
    	tell current location of network preferences
    		set VPNservice to service "MYVPN" -- name of the VPN service
    		if exists VPNservice then connect VPNservice
    	end tell
    end tell
    
    If you want, I can make so that it will bring up a prompt where you can hit disconnect to change back to another Location.

    Here is a script to prompt for disconnection. It will wait until you select disconnect and it will switch to a new location. Be sure to put in the Location you want. I have used Automatic, but presumably you would want one that has airport deactivated.

    Code:
    do shell script "/usr/sbin/scselect Airport-VPN"
    
    delay 5
    
    tell application "System Events"
    	tell current location of network preferences
    		set VPNservice to service "MYVPN" -- name of the VPN service
    		if exists VPNservice then connect VPNservice
    	end tell
    end tell
    
    -- Prompt for disconnection
    set userReply to button returned of (display dialog "Click Disconnect when ready to disconnect:" buttons {"Disconnect"})
    if userReply is "Disconnect" then do shell script "/usr/sbin/scselect Automatic" -- Insert your location
     
  3. marvin*1*2 thread starter macrumors member

    marvin*1*2

    Joined:
    Jun 19, 2007
    Location:
    Yrp!
    #3
    cheers for that one calderone, i'll keep it in mind
    but i fiddled some with it and got it working now at least for the time being...
    turned out that if I release the mouse button in between an action in record mode, the mouse pointer loses focus in playback mode.
    so, click on airport icon, wait for menu to popup while still holding the mouse butn, release on 'turn airport on/off' - that's how it seems to work fine. no more mouse in the wrong place.
     
  4. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #4
    I am not personally a fan of recorded automator actions. I personally think this sounds like a case where a script and locations would be a better solution.

    Glad you got it working though.
     
  5. marvin*1*2 thread starter macrumors member

    marvin*1*2

    Joined:
    Jun 19, 2007
    Location:
    Yrp!
    #5
    yeah I know what u mean. u don't really know what's the f***s happening, one day it works, another it doesn't anymore. but then again, high level scripting languages are just the same really... and besides, I just can't be bothered anymore wasting my brain on bull like that. I like the LEGO programming style :D, i want stuff to just work and make my day easier and not get on my balls.
    that's why I got me a mac eventually ;)
     
  6. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #6
    I would say the Lego automator actions break before a high level language like applescript. It would "get on your balls" sooner than my script above.

    I threw that script together in about a minute. And now, I have a framework for getting any thing like this done. You would spend more time remaking an automator action than say changing this script to a new command or whatever change may come in an OS revision. It is also more universal. To each their own.
     

Share This Page