How do I open network preferences and connect to a specific network?

I just learned about terminal today from my IT guy. I am trying to put together an automator application that will open up terminal and then using script tell terminal to connect to a specific network “VPN (L2TP)” if it is not connected already. I have tried looking through some of the posts but to be honest I’m not good enough to understand if the answer is already there.

swimwolfe

Hi,

try this


tell application "System Events"
	tell network preferences
		tell current location
			set VPNSservice to a reference to (first service whose kind is 8 and name is "VPN (L2TP)")
			if exists VPNSservice then connect VPNSservice
		end tell
	end tell
end tell

This worked great! Thanks for the help!