Forked from gabriel-r/Open Safari|Chrome URL in Other Browser.scpt
Last active
January 27, 2018 22:39
-
-
Save warmlogic/e6b2f30640b4c5de2077373fb53f6df3 to your computer and use it in GitHub Desktop.
Open in Chrome from Safari and vice versa
This file contains hidden or 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
-- adapted from https://gist.github.com/gabriel-r/f98886d589682d1429744bdbfbfbe11a | |
-- Create as an Automator Service: Receives "no input" in "any application" | |
-- System Preferences > Keyboard > Shortcuts > Services: Set keyboard shortcut (e.g., Cmd-Shift-E) | |
-- Must select URL in browser (Cmd-L) before triggering with keyboard shortcut | |
tell application "System Events" | |
set activeApp to name of first application process whose frontmost is true | |
if "Safari" is in activeApp then | |
set theURL to missing value | |
tell application "Safari" | |
if (exists window 1) then | |
if (URL of current tab of window 1 does not start with "favorites://") then | |
set theURL to URL of front document | |
end if | |
end if | |
end tell | |
if theURL is not equal to missing value then | |
tell application "Google Chrome" | |
if (count of (every window where visible is true)) is greater than 0 then | |
tell front window to make new tab | |
else | |
make new window | |
end if | |
set URL of active tab of front window to theURL | |
activate | |
end tell | |
tell application "Safari" | |
close current tab of front window without saving | |
end tell | |
end if | |
else if "Google Chrome" is in activeApp then | |
set theURL to missing value | |
tell application "Google Chrome" | |
if (exists window 1) then | |
if (URL of active tab of window 1 does not start with "chrome://") then | |
set theURL to URL of active tab of window 1 | |
end if | |
end if | |
end tell | |
if theURL is not equal to missing value then | |
-- https://discussions.apple.com/thread/2770617?start=15&tstart=0 | |
tell application "Safari" | |
activate | |
try | |
tell window 1 to set current tab to make new tab | |
set URL of document 1 to theURL | |
on error | |
open location theURL | |
end try | |
end tell | |
end if | |
tell application "Google Chrome" | |
if (exists window 1) then | |
delete tab (active tab index of window 1) of window 1 | |
end if | |
end tell | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment