Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save whitemuu/bea98832ddb9862641a727b2c2d69767 to your computer and use it in GitHub Desktop.
Save whitemuu/bea98832ddb9862641a727b2c2d69767 to your computer and use it in GitHub Desktop.
function switchBrowser()
local current = hs.application.frontmostApplication()
local bool,URL
if (current:name() == "Google Chrome") then
bool,URL = hs.osascript.applescript('tell application "Google Chrome" to get URL of active tab of window 0')
if bool then
if (string.match(URL,'chrome://')) then
hs.alert('not a valid link')
else
hs.execute('open -a Safari "' .. URL .. '"')
end
else
hs.alert('error getting URL')
end
elseif (current:name() == "Safari") then
bool,URL = hs.osascript.applescript('tell application "Safari" to get URL of document of window 0')
if bool then
if (string.match(URL,'favorites://')) then
hs.alert('not a valid link')
else
hs.execute('open -a "Google Chrome" "' .. URL .. '"')
end
else
hs.alert('error getting URL')
end
else
hs.alert('no focused browser')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment