Discussion:
execute script on exit
gt
2011-01-25 10:31:08 UTC
Permalink
Hello guys, as the subject suggests, i want to know if cmus supports
executing some script on exit. I want to remove a text file which is
used by conky to display the currently playing song in cmus.

When i close cmus, i want the file to be removed along with it, so that
conky doesn't keep on displaying the last played song.

Or is there any other way to execute a script when exiting from cmus.
gt
2011-01-25 11:21:10 UTC
Permalink
Post by gt
Hello guys, as the subject suggests, i want to know if cmus supports
executing some script on exit. I want to remove a text file which is
used by conky to display the currently playing song in cmus.
When i close cmus, i want the file to be removed along with it, so that
conky doesn't keep on displaying the last played song.
Or is there any other way to execute a script when exiting from cmus.
Nevermind, i used a conditional (if_existing file) in conky to first
see if the cmus socket exists, and only then display content from the
status file. So no need to delete the file now.

But, still i would like to know if we can execute a script on cmus exit.
Johannes Weißl
2011-01-25 11:38:20 UTC
Permalink
Post by gt
Hello guys, as the subject suggests, i want to know if cmus supports
executing some script on exit. I want to remove a text file which is
used by conky to display the currently playing song in cmus.
When i close cmus, i want the file to be removed along with it, so that
conky doesn't keep on displaying the last played song.
Or is there any other way to execute a script when exiting from cmus.
I don't think it is supported in cmus right now, but can't you just use
this wrapper script:

~/bin/cmus:
-----------------------
#!/bin/bash
/usr/bin/cmus "$@"
rm -f "$FILE_TO_REMOVE"
-----------------------

You can also keep this script always running:
-----------------------------------------------------
#!/bin/bash
while true ; do
x=$(inotifywait -e delete --format %f -r $HOME/.cmus)
if [ "$x" = socket ] ; then
rm -f "$FILE_TO_REMOVE"
fi
done
-----------------------------------------------------

Probably there are more options (lsof, ...). Is that sufficient for your
case?



Johannes
gt
2011-01-25 12:21:58 UTC
Permalink
Post by Johannes Weißl
I don't think it is supported in cmus right now, but can't you just use
-----------------------
#!/bin/bash
rm -f "$FILE_TO_REMOVE"
-----------------------
-----------------------------------------------------
#!/bin/bash
while true ; do
x=$(inotifywait -e delete --format %f -r $HOME/.cmus)
if [ "$x" = socket ] ; then
rm -f "$FILE_TO_REMOVE"
fi
done
-----------------------------------------------------
Probably there are more options (lsof, ...). Is that sufficient for your
case?
Thanks Johannes, i got the problem sorted using a built-in conky option.
Still thanks for the script. Actually, my scripting skills are almost
non-existent, so i didn't know that such a wrapper could have done the
job. I really need to learn bash :P

Loading...