From the Terminal

How to make a launcher for Spotify in Linux that works with Spotify links

When launching Spotify in Linux by default the deb package comes with a desktop file that contains an exec that essentially just runs the "spotify" binary. Spotify does have a dbus interface for certain things. We can look for an existing process and if one is found we throw the Spotify link into dbus instead of opening another Spotify instance.

I wrote a simple launcher replacement. Just set your desktop file to use this instead of the default.

#!/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