Created
May 11, 2018 10:10
-
-
Save whitemuu/bea98832ddb9862641a727b2c2d69767 to your computer and use it in GitHub Desktop.
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
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