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

marvin*1*2

macrumors member
Original poster
Jun 19, 2007
90
0
Yrp!
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.
 

calderone

Cancelled
Aug 28, 2009
3,743
352
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
 

marvin*1*2

macrumors member
Original poster
Jun 19, 2007
90
0
Yrp!
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.
 

calderone

Cancelled
Aug 28, 2009
3,743
352
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.

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.
 

marvin*1*2

macrumors member
Original poster
Jun 19, 2007
90
0
Yrp!
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 ;)
 

calderone

Cancelled
Aug 28, 2009
3,743
352
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 ;)

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.