Skip to content

Instantly share code, notes, and snippets.

@dizk
Last active November 4, 2022 13:01
Show Gist options
  • Save dizk/7595732 to your computer and use it in GitHub Desktop.
Save dizk/7595732 to your computer and use it in GitHub Desktop.
Get artist and song from spotify in terminal. (For conky etc.)
#!/bin/bash
if [[ "$(dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames)" == *org.mpris.MediaPlayer2.spotify* ]]; then
# Artist
artist=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk '/artist/{getline; getline; split($0,a,"\""); print a[2]}')
# Song
song=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk '/title/{getline; split($0,a,"\""); print a[2]}')
# Print
echo $artist - $song
else
echo "Spotfy is not running / cant find dbus service"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment