diff --git a/triggershell.yml b/triggershell.yml index 11e38a0..8bb322b 100644 --- a/triggershell.yml +++ b/triggershell.yml @@ -378,6 +378,33 @@ scripts: timeoutSeconds: 20 variables: [] + - id: spotify-stop + name: "Spotify: Stop Playback" + description: >- + Pauses Spotify playback on the local session via its MPRIS D-Bus + interface. Does nothing if Spotify is not running. + command: bash + args: + - -c + - | + # triggershell.service starts before the graphical session and has no + # DBUS_SESSION_BUS_ADDRESS, so point dbus-send at the user bus socket + # directly (systemctl --user works here, so this socket exists). + bus="unix:path=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/bus" + if ! dbus-send --bus="$bus" --print-reply --dest=org.freedesktop.DBus \ + /org/freedesktop/DBus org.freedesktop.DBus.ListNames 2>/dev/null \ + | grep -q '"org.mpris.MediaPlayer2.spotify"'; then + echo "Spotify is not running." + exit 0 + fi + exec dbus-send --bus="$bus" --print-reply --type=method_call \ + --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 \ + org.mpris.MediaPlayer2.Player.Pause + - spotify-stop + cwd: ./ + timeoutSeconds: 15 + variables: [] + - id: system-shutdown name: "System: Shutdown" description: >-