You are not logged in.
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
Wow did not think I could find a solution myself but I did
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
CMD=$(mpc | sed -n 's/\[playing\].*/mpc\ play/p');
sh script
$CMDI 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
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
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.
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 +5Offline