aboutsummaryrefslogtreecommitdiff
path: root/scripts/media_control.sh
blob: f2e6612add69906f8223070f0ec2efc6756569d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

#TODO
# NOTE:
# if spotify is running toggle is consumed by spotify.

# arg parsing
if [ "$1" = "toggle" ]
then
    spotify_cmd="PlayPause"
elif [ "$1" = "next" ]
then
    spotify_cmd="Next"
elif [ "$1" = "prev" ]
then
    spotify_cmd="Previous"
fi

if [ "$spotify_cmd" != "" ]
then
    # can't be sure if spotify was running and should play again
    if [ "$spotify_cmd" = "PlayPause" ]
    then
        if [ "$(ps -A | grep spotify)" != "" ]
        then
            dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$spotify_cmd
        else
            mpc $1
        fi
    elif [ "$(lsof | grep /dev/snd | grep spotify)" != "" ]
    then
        dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$spotify_cmd
    elif [ "$(mpc | grep '\[' | cut -f1 -d' ')" != "" ]
    then
        mpc $1 &>/dev/null
    fi
fi