Hi. I'm trying to get a script working that basically disconnects my internet if the vpn goes out. I found a script on lifehacker that will automatically reconnect the vpn if it fails, and I took that and modified it into this.
But I noticed that it didnt work properly (nothing happened when I manually disconnected it.
So I looked up a way to turn wifi off in apple script, and I attempted to manipulate that bit of code into the original script. I resulted with this bit of code, which also failed to work properly.
Is there a way to fix this? I'm relativley new to applescript (I used it to write an autotyper one time), so any help would be appreciated. The objective is to make it run as an always running .app (like the original lifehacker), and to have it instantly pull the plug on the internet the second the VPN drops. I will bake cookies for anyone who is willing to help/correct my thought process.
Love,
Ring
But I noticed that it didnt work properly (nothing happened when I manually disconnected it.
Code:
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "BTGuard VPN"
set failsafe to the service "Wi-Fi"
if myConnection is not null then
if current configuration of myConnection is not connected then
disconnect failsafe
end if
end if
end tell
return 120
end tell
So I looked up a way to turn wifi off in apple script, and I attempted to manipulate that bit of code into the original script. I resulted with this bit of code, which also failed to work properly.
Code:
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "BTGuard VPN"
set status to do shell script "/usr/sbin/networksetup -getairportpower en1 | awk '{ print $4 }'"
if status = "On" then
do shell script "/usr/sbin/networksetup -setairportpower en1 off"
if myConnection is not null then
if current configuration of myConnection is not connected and status = "On" then do shell script "/usr/sbin/networksetup -setairportpower en1 off"
end if
end if
end tell
return 120
end tell
end idle
Is there a way to fix this? I'm relativley new to applescript (I used it to write an autotyper one time), so any help would be appreciated. The objective is to make it run as an always running .app (like the original lifehacker), and to have it instantly pull the plug on the internet the second the VPN drops. I will bake cookies for anyone who is willing to help/correct my thought process.
Love,
Ring
Last edited: