Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPD: receive actual mpd-status with Linux bash script

I want to know how to receive the actual status of the mpd player with a linux bash script. I know how to start and stop the player...

#!/bin/bash
mpc play
mpc volume +1
mpc stop

...but i need to know if mpd is playing a song or not. Also the current volume setting is interesting.

I tried to receive it with mpcstatus=cat /var/tmp/mpd_status or actvol=cat /var/tmp/mpd_volume but the files do not exist. I'm working with Volumio/Debian on a RaspberryPi.

like image 727
WBK Avatar asked Oct 19 '22 11:10

WBK


1 Answers

I've got it!

Play:

if mpc status | grep playing >/dev/nul      # If mpd is playing
then
 command... 
fi

Volume:

ACTVOL=`mpc status | sed -n '/volume/p' | cut -c8-10 | sed 's/^[ \t]*//'`
like image 127
WBK Avatar answered Nov 02 '22 11:11

WBK