From 1a102c45a442490c1f1efdcf769b2ead579cfff6 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 3 Feb 2023 11:02:06 -0700 Subject: Make spotify-control more flexible --- extras/HOME/.local/bin/spotify-control | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'extras') diff --git a/extras/HOME/.local/bin/spotify-control b/extras/HOME/.local/bin/spotify-control index 1bd7bcc..34a2633 100755 --- a/extras/HOME/.local/bin/spotify-control +++ b/extras/HOME/.local/bin/spotify-control @@ -6,16 +6,36 @@ then exit fi +target_hint="spotify" +while [[ "$1" == --* ]] ; do + arg="$1" + case "$arg" in + --target-hint=*) + target_hint="${arg/--target-hint=/}" + ;; + *) + echo "Bad Argument $1" + exit 1 + ;; + esac + shift +done + # Some targets (spotifyd) don't have a stable dbus path. -target="$( \ +targets="$( \ dbus-send \ --print-reply \ --dest=org.freedesktop.DBus \ /org/freedesktop/DBus org.freedesktop.DBus.ListNames \ | sed 's#.*string \"\(.*\)"#\1#' \ - | grep MediaPlayer2 \ - | head -n1)" + | grep MediaPlayer2)" +# Prefer the target hint. +target="$(echo "$targets" | grep -i "$target_hint" | head -n1)" +if [ -z "$target" ] ; then + # If no spotify, pick an arbitrary one + target="$(echo "$targets" | head -n1)" +fi function mpris2_dbus_player_do { dbus-send \ -- cgit