How to Script VPN Connect in Leopard?

Hi Everyone,

I have a relatively simple script that automates a VPN connection (using Apple’s VPN Connect) to my wife’s work server. It simply told the application Internet Connect to activate, and the rest would take care of itself. But Leopard doesn’t have Internet Connect as a freestanding application. Rather, VPN connections are now within the Network preference pane. So, how do I tell AS to launch a VPN connection from inside Leopard’s Network Prefs? I think it should be simple, but I couldn’t find any clues online. Thanks in advance.

Joe

Hi,

the scriptability of network preferences has been massively improved in Leopard

Try this

tell application "System Events"
	tell current location of network preferences
		set VPNservice to service "VPN (L2TP) 2" -- name of the VPN service
		if exists VPNservice then connect VPNservice
	end tell
end tell

Thanks, Stefan! I’ll give it at try when I get home. I figured it would be improved in Leopard, but it wasn’t obvious to me how to identify the VPN’s location. It makes perfect sense, though, given your code.

Joe

Hi Stefan (and Everyone),

It worked like a charm. May I impose on you, though, for one last bit of help? How do I check if the VPN is active? With Internet Connect it was pretty simple, but not sure how to do it in Leopard. The idea is to make sure the VPN is connected before mounting network drives. Thanks in advance.

Joe

try this


tell application "System Events"
	tell current location of network preferences
		set VPNservice to service "VPN (L2TP) 2" -- name of the VPN service
		set isConnected to connected of current configuration of VPNservice
		if isConnected then
			-- do something
		end if
	end tell
end tell

That’s great for a VPN, but I use to use tell “internet connect” to connect, to dail up to the internet. Now all my scripts don’t work anymore in Leopard.

Internet Connect.app has vanished in Leopard, use network preferences in System Events instead

I missed the
–tell current location of network preferences–
now it works!!

I do it like this now:

tell application "System Events"
	tell current location of network preferences
		set Modemdailup to service "HUAWEI"
		if exists Modemdailup then connect Modemdailup
	end tell
end tell

sorry to bring this back from dead,

I am trying to get the “time connected” of current modem connection.

its the time that shows on menu bar and tells how long you have been connected to internet via modem.

on “Internet Connect” it was seconds connected.

any ideas?
thanks alot