r/applescript • u/fowlergmu • Jul 01 '24
Request: Script to automatically turn on VPN in System Settings
Hello, I'm just looking for a way to automatically turn on a VPN profile in my system settings, or to see if this is even an option. Ideally, I'd like to load the script on a streamdeck to turn on and off my VPN with just a button. Any ideas of where to start?
4
Upvotes
1
u/Kina_Kai Jul 01 '24
Shortcuts has this as an action. You could directly use that and just export the shortcut as an app, and trigger it on the Streamdeck.
1
u/aew3 Jul 01 '24
Very easy to do this in the shell:
scutil --nc [start/stop] [vpnName]Many ways to trigger this script from a key press. My preference is alfred, but you can do this in shortcuts too.
1
u/Active-Bass4745 Jul 01 '24
Sorry, not sure what I'm doing wrong with the code formatting, but this should do what you want, including connecting to a server.
-- Global settings
property theVPN : "VNet_Name" -- Name of VPN
property connectionAttempts : 20 -- Number of seconds to attempt connecting to VPN
property repositoryName : "name-of-repository" -- Name of repository to connect to
property ipAddress : "XXX.XXX.XXX.XXX" -- IP address
property serverName : "name-of-file-share" -- Name of server to connect to
-- connect directly to VPN
try
on error errmsg number errnum
end try
-- Wait for connection to be established
set isConnected to my checkConnection()
if (not isConnected) then
end if
-- If VPN is connected, then connect to cloud server
if (isConnected) then
else
end if
-- Verify connected to VPN
on checkConnection()
end checkConnection