>Using Scripts to Control MOC Playback

>MOC to play or pause


#! /bin/bash
STOP=`mocp -i | grep State: STOP | cut -c8-13`
PLAY=`mocp -i | grep State: PLAY | cut -c8-12`
PAUSE=`mocp -i | grep State: PAUSE | cut -c8-13`
if [ “$STOP” == “STOP” ]; then
mocp -p && sleep 1s && notify-send “Playback” “`mocp -i | grep State: | cut -c8-13`”
elif [ “$PAUSE” == “PAUSE” ]; then
mocp -G && sleep 1s && notify-send “Playback” “`mocp -i | grep State: | cut -c8-13`”
elif [ “$PLAY” == “PLAY” ]; then
mocp -G && sleep 1s &&  notify-send “Playback” “`mocp -i | grep State: | cut -c8-13`”
else
notify-send “Error MOCP not running” “Please run MOCP”
fi


MOC to stop

#! /bin/bash
STOP=`mocp -i | grep State: STOP | cut -c8-13`
PLAY=`mocp -i | grep State: PLAY | cut -c8-12`
PAUSE=`mocp -i | grep State: PAUSE | cut -c8-13`


if [ “$STOP” == “STOP” ]; then
notify-send -t 1000 “Playback” “Already stopped”
elif [ “$PAUSE” == “PAUSE” ]; then
mocp -s && sleep 1s && notify-send -t 1000 “Playback” “stopped”
elif [ “$PLAY” == “PLAY” ]; then
mocp -s && sleep 1s &&  notify-send -t 1000 “Playback” “stopped”
else
notify-send “Error MOCP not running” “Please run MOCP”
fi

MOC to playing next song

#! /bin/bash
STOP=`mocp -i | grep State: STOP | cut -c8-13`
PLAY=`mocp -i | grep State: PLAY | cut -c8-12`
PAUSE=`mocp -i | grep State: PAUSE | cut -c8-13`
if [ “$STOP” == “STOP” ]; then
notify-send -t 1000 “Playback” “stopped”
elif [ “$PAUSE” == “PAUSE” ]; then
mocp -f && sleep 1s && notify-send -t 1000 “MOC” “`mocp -i | grep SongTitle`”
elif [ “$PLAY” == “PLAY” ]; then
mocp -f && sleep 1s &&  notify-send -t 1000 “MOC” “`mocp -i | grep SongTitle`”
else
notify-send “Error MOCP not running” “Please run MOCP”
fi

MOC to playing previous song

#! /bin/bash
STOP=`mocp -i | grep State: STOP | cut -c8-13`
PLAY=`mocp -i | grep State: PLAY | cut -c8-12`
PAUSE=`mocp -i | grep State: PAUSE | cut -c8-13`
if [ “$STOP” == “STOP” ]; then
notify-send -t 1000 “Playback” “stopped”
elif [ “$PAUSE” == “PAUSE” ]; then
mocp -r && sleep 1s && notify-send -t 1000 “MOC” “`mocp -i | grep SongTitle`”
elif [ “$PLAY” == “PLAY” ]; then
mocp -r && sleep 1s &&  notify-send -t 1000 “MOC” “`mocp -i | grep SongTitle`”
else
notify-send “Error MOCP not running” “Please run MOCP”
fi

and then you can bind the multimedia keys with the command 😀
using xbindkeys
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *