tell application "Google Chrome"
if frontmost then
set w to window 1
if visible of w is true and (URL of active tab of w) contains "music/listen" then
-- Chrome uses minimized instead of miniaturized
set minimized of w to true
return
end if
end if
activate
set i to 0
repeat with w in (windows)
set i to i + 1
set j to 0
repeat with t in (tabs of w)
set j to j + 1
if URL of t contains "music/listen" then
set (active tab index of w) to j
set index of w to 1
tell application "System Events" to tell process "Google Chrome"
perform action "AXRaise" of window 1 -- `set index` doesn't always raise the window
-- keystroke "f" using {option down, command down}
end tell
return
end if
end repeat
end repeat
activate
set w to make new window
-- set URL of active tab of w to "https://play.google.com/music/listen"
-- wait for the tab to load so js can run
delay 1
-- this needs developer access - alternatively use the "set URL" line above
execute of active tab of w javascript "window.open('https://play.google.com/music/listen','window','toolbar=no, menubar=no, location=no, resizable=yes noopener=yes')"
close w
end tell
It would be great if there was a shortcut that creates a new Play Music panel (without tabs etc) or switches to it if it exists. That way,
I have some code at https://github.com/wmertens/global-chrome-tab for opening tabs with a global shortcut, but right now I'm using this applescript: