Skip to content

Instantly share code, notes, and snippets.

@simonbru
Last active June 29, 2022 13:20
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 simonbru/0409852bf2a3f7d81667ac2ed64117f7 to your computer and use it in GitHub Desktop.
Save simonbru/0409852bf2a3f7d81667ac2ed64117f7 to your computer and use it in GitHub Desktop.
Open spotify URLs in open Spotify instance
#!/bin/sh
# CLI wrapper that works around a bug with Spotify's handling of URIs.
# See https://community.spotify.com/t5/Desktop-Linux/Linux-Spotify-URI-only-opens-start-page/m-p/1675578#M1812
uri="$1"
echo "Trying to play: \"$uri\""
if ! qdbus org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 \
org.mpris.MediaPlayer2.Player.OpenUri \
"$uri"
then
echo "No Spotify instance seems to be open."
echo "Opening URI with new instance."
# use "--no-zygote" to prevent occasional crashes on startup:
# https://wiki.archlinux.org/index.php/Spotify#Crashes_on_startup
spotify --no-zygote --uri="$uri" &
fi
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Name=spotify-open
TryExec=spotify-open
Exec=spotify-open %u
Terminal=false
NoDisplay=true
MimeType=x-scheme-handler/spotify;
StartupNotify=false
[Desktop Entry]
Type=Application
Name=Spotify
GenericName=Music Player
Icon=spotify-client
TryExec=spotify
# Spotify currently only supports opening one URI with "--uri=%u"
# https://community.spotify.com/t5/Desktop-Linux/Linux-Spotify-URI-only-opens-start-page/m-p/1675578#M1812
# Use "--no-zygote" to prevent occasional crashes on startup:
# https://wiki.archlinux.org/index.php/Spotify#Crashes_on_startup
Exec=spotify --no-zygote --uri=%u
Terminal=false
# Stop opening URLs directly with spotify because it opens a new instance everytime.
# Let "spotify-open" handle it.
# MimeType=x-scheme-handler/spotify;
Categories=Audio;Music;Player;AudioVideo;
StartupWMClass=spotify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment