Skip to content

Instantly share code, notes, and snippets.

@bcosynot
Created August 24, 2022 16:02
Show Gist options
  • Save bcosynot/a010acb4a897c5f7337d622567b36a85 to your computer and use it in GitHub Desktop.
Save bcosynot/a010acb4a897c5f7337d622567b36a85 to your computer and use it in GitHub Desktop.
Automatically close tab opened by your VPN connection
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