But it's not as fast as I like. I also have this applescript for doing the same thing from Safari side which is really fast :
if application "Safari" is running then
tell application "Safari"
try
set currentSafariURL to URL of current tab of front window
set pageName to name of current tab of front window
on error
return "There are no pages open in Safari at the moment"
end try
end tell
tell application "Google Chrome"
activate
# If Chrome has no windows open make a new window
if (count of windows) is 0 then make new window
set currentChromeURL to URL of active tab of front window
# Don't do anything if the page is already open in Chrome
if currentChromeURL is not currentSafariURL then
# If the active tab is in use make a new tab
if currentChromeURL is not "chrome://newtab/" then
make new tab at end of tabs of front window
end if
# Open the URL from Safari
set URL of active tab of front window to currentSafariURL
else
return "The current Safari tab is already open in Chrome"
end if
end tell
# Enable the following line to post notifications after sending URLs to Chrome
--return "Opening '" & pageName & "' in Chrome"
else
return "Safari is not open at the moment"
end if
I tried to fiddle with the script in Script Debugger but I don't really know how to convert it to do the same thing but from chrome side.
tell application "Google Chrome"
set tab_list to every tab in the front window
repeat with the_tab in tab_list
set the_url to the URL of the_tab
tell application "Safari" to open location the_url
end repeat
end tell
I am just not sure how to then switch to the correct tab in Safari.
if application "Google Chrome" is running then
tell application "Google Chrome"
try
set currentChromeURL to URL of active tab of front window
set pageName to title of active tab of front window
on error
return "There are no pages open in Chrome at the moment"
end try
end tell
tell application "Safari"
activate
# If Safari has no windows open make a new window
if (count of windows) is 0 then make new window
set currentSafariURL to URL of current tab of front window
# Don't do anything if the page is already open in Safari
if currentSafariURL is not currentChromeURL then
# If the current tab is in use make a new tab with the current Chrome URL
if currentSafariURL is not "favorites://" then
tell window 1
set current tab to (make new tab with properties {URL:currentChromeURL})
end tell
end if
# If the current tab is showing Favorites, open the URL from Chrome
set URL of current tab of front window to currentChromeURL
else
return "The current Chrome tab is already open in Safari"
end if
end tell
# Enable the following line to post notifications after sending URLs to Chrome
--return "Opening '" & pageName & "' in Chrome"
else
return "Safari is not open at the moment"
end if
One caveat: this assumes that new Safari tabs open with Favorites. If you have new tabs or windows set to open a different URL, you’ll need to modify this line in the script to that URL:
One further thought: if you really want the absolute fastest performance, you may be able to eke out a few more milliseconds with a compiled script file rather than a text script. Try downloading and unzipping this:
Move the unzipped script file somewhere safe (perhaps a Scripts folder on Dropbox or the like) then drag it into the appropriate KM macro to automatically create an Execute an AppleScript action that runs the compiled script rather than the text version (make sure to disable or delete the old text-based version if you do this, of course). I can't guarantee this will be noticeably faster, but if you want fastest, this is it
Personally, I tend to use an AppleScript solution that looks at the current Chrome/Safari state and decides whether to open a new window or not, but for the simple case, this action is pretty easy and fast.
That script - to look at the current Chrome/Safari state and decide whether to open a new window or not - that's what I want to do. Would I be able to get that script?
My issue is that I want to know if a url is already being used and if it is, then to go to that tab, and if not, create a new tab.
What's happening is that as I'm working on my computer, a student will message me in Google Classroom. I go to their message, then possibly need to get to one of the other Google Classroom pages I've set up in stream Deck. When I execute that button, it opens a new tab, even if perhaps that url may already be open in one of the existing tabs. It would save some clutter if I could go to the already open on.