You are not logged in.

#1 2014-09-02 18:32:09

faiden
Member
Registered: 2014-03-08
Posts: 22

[SOLVED]Help with a mpd/mpc script

Hi I was wondering if some kind soul could help me with a  script.

This is what I want the script to do:

[mpc pause]

(other script mine is a newscast)

[mpc start playing again ONLY if it was playing music before] if  music was not playing before it just stays paused

Last edited by faiden (2014-09-03 10:37:17)

Offline

#2 2014-09-02 18:57:29

faiden
Member
Registered: 2014-03-08
Posts: 22

Re: [SOLVED]Help with a mpd/mpc script

Wow did not think I could find a solution myself but I did big_smile I bet there is much better ways to do it.

I made [mpc pause] write a file saying playing=yes/no

and then read that file at the [mpc start]

Offline

#3 2014-09-03 01:17:07

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [SOLVED]Help with a mpd/mpc script

CMD=$(mpc | sed -n 's/\[playing\].*/mpc\ play/p');
sh script
$CMD

 I used sed to avoid an additional if statement, since grepping the status would be necessary either way.

Edit: Should you consider this issue solved, then please mark the thread as such.

Last edited by emeres (2014-09-03 01:32:35)

Offline

#4 2014-09-03 10:29:56

faiden
Member
Registered: 2014-03-08
Posts: 22

Re: [SOLVED]Help with a mpd/mpc script

I found another solution by adding at before the script

for i in `seq 1 11`; do sleep 0.5 ; mpc volume -5; done

and this after the script

for i in `seq 1 11`; do sleep 0.5 ; mpc volume +5; done

Offline

#5 2014-09-03 11:01:38

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [SOLVED]Help with a mpd/mpc script

 Use [⁣code][⁣/code] tags to mark output of a command or scripts. Also refrain from using backticks, use $() instead, so in your case:

for i in $(seq 1 11); do sleep 0.5; mpc volume -5; done;
script;
for i in $(seq 1 11); do sleep 0.5; mpc volume +5; done;

 It does not really matter for something as simple as seq, but it is a good practice to make it a habit.

Open Group wrote:

Because of these inconsistent behaviors, the backquoted variety of command substitution is not recommended for new applications that nest command substitutions or attempt to embed complex scripts.

 Since the sequence is run only twice it does not really matter, but should you want to change it often or run it multiple times or in multiple variations, consider using it as a function:

mpc-fade() {
for i in $(seq 1 $1); do sleep $2; mpc volume $3; done;
}

mpc-fade 11 0.5 -5
script
mpc-fade 11 0.5 +5

Offline

Board footer

Powered by FluxBB