Skip to content

Instantly share code, notes, and snippets.

@dillonhafer
Last active October 24, 2017 16:43
Show Gist options
  • Save dillonhafer/d7da8bda1005a6a32f859574dde686b0 to your computer and use it in GitHub Desktop.
Save dillonhafer/d7da8bda1005a6a32f859574dde686b0 to your computer and use it in GitHub Desktop.
Get currently playing song/artist in Google Play
#!/usr/bin/osascript
#
# Usage ./safari-google-song.osa [tab url]
#
# Example: ./safari-google-song.osa play.google.com
# Example: ./safari-google-song.osa spotify.com
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on run argv
if (count of argv) > 0 then
set _url to (item 1 of argv)
else
set _url to "play.google.com"
end if
tell application "Safari"
set tabsList to front window's tabs as list
set tabsInfo to {}
repeat with currTab in tabsList
set currHost to do Javascript "window.location.host" in currTab
if (currHost = _url) then set raw_title to do Javascript "document.title" in currTab
end repeat
end tell
try
set song to replace_chars(raw_title, " - Google Play Music", "")
log ("♪ " & song & " ♫")
on error
log "There's no song playing"
end try
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment