You are not logged in.
Hi guys, I've just made it over from the #! forums, I was Dave6 on there due to the unallowed "^"... hehe!
So, to jump straight in, I'm trying to delete current playing track in mplayer, and found this solution:
http://superuser.com/questions/663247/i … in-mplayer
#/bin/bash
# rmplaying.sh
# only works when exactly 1 instance of mplayer is running
function playing {
PID=`pidof mplayer`
WHICH=`which mplayer`
if [ $PID ]; then
lsof -p $PID | awk '{ if ($5=="REG" && $4!="mem" && $9)print $0 }' | grep -v "$WHICH" | grep -oP '\/.*'
fi
}
FILE="$(playing)"
echo "file: $FILE"
if [ "$FILE" ]; then
rm "$FILE" && echo "Removed '$FILE'"
fi
I don't understand the WHICH variable, can someone assist please?
Thanks
Last edited by Dave^ (2016-02-02 19:55:09)
Offline
WHICH is set to the full PATH of the external command 'mplayer'.
The backquotes cause a subshell to run the command 'which mplayer' and substitute the output of that command (the full path to mplayer, presumable /usr/bin/mplayer). The assignment then assigns that value to the variable WHICH.
Offline
Brilliant, thanks. I shoulda guessed that.
So now, running the script "rmplaying.sh" manually works, but I can't get the shortcut within the mplayer terminal window to work.
/home/dave/rmplaying.sh: 4: /home/dave/rmplaying.sh: function: not found
/media/dave/filename.mp3
/home/dave/rmplaying.sh: 10: /home/dave/rmplaying.sh: Syntax error: "}" unexpected
Any pointers? (I hate "gimme answer" posts, but I'm stuck here!)
Offline
#/bin/bash
should be
#!/bin/bash
Offline
Gawd, I looked at that and thought it didn't look right.
Proper n00b! :8
Many thanks!
Offline