On a Mac, how can access to a network share be established with just one click, regardless of the connected WiFi network? AppleScript allows you to determine the currently connected WiFi and then either directly mount the network share or, if the Mac is not connected to the WiFi network that contains the network drive, first establish the suitable VPN connection. This way, especially with a MacBook, a connection to a share folder or NAS can always be established regardless of the current location and the connected network. This eliminates the need for the user to manually enter network paths in the Finder and establish the VPN connection. The script thus allows less IT-savvy people with a Mac to access network storage from any location with an Internet connection.
set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
if SSID is "Wifi Name" or SSID is "Wifi Name" then
try
mount volume "smb://user:pass@192.168.100.100/Share"
end try
display notification "Connected to own WiFi, share is mounted" with title "MountNAS"
else
display notification "Connected to another WiFi, VPN connection is established before mounting share." with title "MountNAS"
tell application "System Events"
tell current location of network preferences
set VPNService to service "VPN Name"
-- determine current VPN connection status
set isConnected to connected of current configuration of VPNService
if isConnected = false then
connect VPNService
delay 6
end if
end tell
end tell
try
mount volume "smb://user:pass@192.168.100.100/Share"
end try
end if
You can create an executable app from the script editor via “Export”. This app can be saved on the desktop and thus allows the connection to the network share with just a double click.
