Created
August 24, 2022 16:02
-
-
Save bcosynot/a010acb4a897c5f7337d622567b36a85 to your computer and use it in GitHub Desktop.
Automatically close tab opened by your VPN connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaultBrowser = "<your browser>" -- Replace with "Google Chrome", "Firefox", "Vivaldi", or your favorite browser | |
function wait(seconds) | |
local start = os.time() | |
repeat until os.time() > start + seconds | |
end | |
urlOpenedByVpn = "<url opened by your vpn oges here>" | |
function closeTabOpenedByVpn(appName, eventType, appObject) | |
if (eventType == hs.application.watcher.activated) then | |
if (appName == defaultBrowser) then | |
wait(1) | |
local success, result = hs.osascript.applescript('tell application "' .. defaultBrowser .. '" to URL of active tab of front window') | |
if result == urlOpenedByVpn then | |
hs.osascript.applescript('tell application "' .. defaultBrowser .. '" to close active tab of front window') | |
end | |
end | |
end | |
end | |
vpnTabCloser = hs.application.watcher.new(closeTabOpenedByVpn) | |
vpnTabCloser:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment