Skip to content

Instantly share code, notes, and snippets.

@hparadiz
Created May 26, 2022 04:32
Show Gist options
  • Save hparadiz/2f9d85920b1a9d3188d7538c8cbb5a4d to your computer and use it in GitHub Desktop.
Save hparadiz/2f9d85920b1a9d3188d7538c8cbb5a4d to your computer and use it in GitHub Desktop.
Properly handles passing a Spotify URI to a running instance of spotify via DBUS
#!/bin/bash
# check if spotify is already running and if so just pass the uri in
if pgrep -f "Spotify/[0-9].[0-9].[0-9]" > /dev/null
then
busline=busline=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri $1
echo "Spotify is already running"
echo "Sending ${busline} to dbus"
if command -v qdbus &> /dev/null
then
qdbus $busline
exit
fi
if command -v dbus-send &> /dev/null
then
dbus-send $busline
exit
fi
echo "No bus dispatcher found."
# otherwise launch spotify
else
spotify $1 &>/dev/null &
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment