Skip to content

Instantly share code, notes, and snippets.

@gaqzi
Last active April 15, 2024 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaqzi/b3de88050bf1caaf8d2661233b51a1ae to your computer and use it in GitHub Desktop.
Save gaqzi/b3de88050bf1caaf8d2661233b51a1ae to your computer and use it in GitHub Desktop.
Open the current playing song on Spotify on Genius.com

To use this in Alfred create a new workflow and then create a new action Run NSAppleScript and paste in the below script.

Note: If you want to run this on the CLI you can remove the on alfred_script(q) and end alfred_script and add #!/usr/bin/env osascript as the first line to run it from the CLI.

See http://sanitarium.se/blog/2024/04/15/day-to-day-automation-using-alfred/#spotify-controller for more context.

There are a couple of different things going on in the pipeline to open the browser:

  • sed -E 's|([ ]+)|-|g'
    • Replace spaces with -
  • iconv -f 'utf-8' -t 'ASCII//TRANSLIT'
    • Convert any non-ASCII characters to their most direct ASCII counterpart. For example, Björn becomes Bjorn and not the localized Bjoern
  • sed -E 's|[^a-zA-Z0-9-]||g'
    • Remove any characters not matching that regex. [^] means anything not in this group
on alfred_script(q)
set newline to "
"
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set track_name to name of current track
set track_artist to artist of current track
set track_album to album of current track
end tell
do shell script "open \"http://genius.com/$(echo '" & quoted form of track_artist & "-" & quoted form of track_name & "' | sed -E 's|([ ]+)|-|g' | iconv -f 'utf-8' -t 'ASCII//TRANSLIT' | sed -E 's|[^a-zA-Z0-9-]||g')-lyrics\""
end if
end alfred_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment