You are not logged in.
Happy New Year everybody!
I have found a script on Mint forum, it makes a sound when emptying the trash can.
https://forums.linuxmint.com/viewtopic.php?t=304391
Well, it does work but not every time. Since I know nothing about writing scripts, I wonder if there is anything missing in it or what's wrong with it. Sometimes it plays the sound twice or one and a half times, sometimes nothing at all, sometimes it works great. The script starts by
Startup, maybe it does start but it goes to "sleep" later? Is there something wrong with timing or delay??
I'm using Mint Xfce and Linux Lite
I would appreciate your help or ideas very much!
Last edited by agashamu (2022-07-10 19:55:53)
Linux Mint Xfce 21.1
Offline
Why not just enable system sounds? See: https://forum.xfce.org/viewtopic.php?id=9424. The default freedesktop sound theme has a "trash-empty" sound (although it is somewhat limited in the number of sound effects). The Smooth sound theme has more supported sound effects.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Hi ToZ and thank you.
System sounds are enabled, I know all your wonderful posts about it, I used them years ago to set up some sounds in my system, they work great. However, trash sound never worked, tried Bolearis that you modified, Freedesktop never worked for me. I do have a list that you posted once, it does not show that trash empty is supported by canberra. Maybe things changed since then and I should set it up again a different way???
Thanks for your reply!
Last edited by agashamu (2021-12-31 21:09:26)
Linux Mint Xfce 21.1
Offline
Does the following play a sound?
First set up the sound theme:
xfconf-query -c xsettings -p /Net/SoundThemeName -s freedesktop
Then try playing the trash empty sound:
canberra-gtk-play -i trash-empty
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Yes, I get the sound.
Linux Mint Xfce 21.1
Offline
Well, we can continue to see if we can get all sound events (including trash-empty) for you. Or I can offer an alternative to the script from the other forums that will play a sound and empty trash at the same time. However, this second option will just be a script, it won't be tied into any gui events like the first option (meaning you'll manually have to run the script to empty the trash).
Which would you prefer?
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Oh, boy...thanks
Would that other script be something like a launcher? I do know that one from some other forums, and I don't
think i like it...so, if you don't mind. I would prefer your first option.
Funny thing is, I removed that script from my /home/ and renamed it then rebooted, and the damn thing still kept playing, better then ever until I removed the Startup entry. How is it possible??
Linux Mint Xfce 21.1
Offline
Try this script instead. It uses built-in gvfs/gio functionality to manage the trash:
#!/bin/bash
if [ $(gio trash --list | wc -l) -gt 0 ]; then
gio trash --empty
canberra-gtk-play -i trash-empty
fi
Create a launcher to run this script and click on the launcher to clear the trash with sound.
Edit: if you want to use the script from the other link, I would suggest adding some code to make sure that only one instance of the script runs at a time (which might be causing the extra sound events):
#!/bin/bash
# make sure that only one instance of this script is running per user
lockfile=/tmp/.trashsound.$USER.lockfile
if ( set -o noclobber; echo "locked" > "$lockfile") 2> /dev/null; then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
echo "trashsoundDEBUG: Locking succeeded" >&2
cd /home/yourusername/.local/share/Trash/files
while true
do
TOT1="$(ls -1 | wc -l)"
sleep 1
TOT2="$(ls -1 | wc -l)"
if [ "$TOT1" -gt "$TOT2" ];
then
mplayer /home/yourusername/Sounds/trash.mp3
fi
done
# can't create lockfile - notify user and quit
else
echo "trashsoundDEBUG: Lock failed, check for existing process and/or lock file and delete - exiting." >&2
exit 1
fi
Last edited by ToZ (2022-01-01 03:24:21)
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Wow ToZ, you have created an artwork here in the middle of New years eve!!! I'm so sorry I didn't mean to put you to work so hard. But I'm happy, tried your modified script from my link and it works wonderful!!! No more duplicate sound so far after emptying the trash can 25-30 times.
I think using your first script with a launcher would've been a "downgrade" for the system, loosing the right-click options and two trash can icons (empty and full), I did find a script like that once, here is the link, they used Zenity for that one:
https://www.linuxquestions.org/question … nd-686708/
Thank you very much for this great job, Happy New Year to you!!! You are the BEST!!!
Last edited by agashamu (2022-01-02 05:58:35)
Linux Mint Xfce 21.1
Offline
Thank you very much for this great job, Happy New Year to you!!! You are the BEST!!!
Why do you think he's wearing shades?
Happy New Year to you too!
Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please!
Offline
Good question, I don't know...
Happy New Year to you Sir!!!
Linux Mint Xfce 21.1
Offline
Hi Wonderful Forum and ToZ!
So Toz fixed or I should say created that great script to play a sound when emptying the trash can. It completely fixed the double playing problem, but still it stops working after some time, (if not been used), I would say, 30-60 minutes after signing in. A logout and back or restart starts it again. Startup activates the script, but then it stops. Is there any way, to put something in the script so it won't go to "sleep"? Or to tell Startup not to kill the process??
Thanks for any ideas!
Linux Mint Xfce 21.1
Offline
Startup activates the script, but then it stops.
That's interesting. A "while true" statement basically runs forever. Is there something else killing it? Anything in your logs/journal about the script stopping or being killed.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Thanks ToZ, is there an "easy way" to bring up the logs/journal report on that script?
Linux Mint Xfce 21.1
Offline
Try the journal. Something like:
journalctl | grep -i NAMEOFSCRIPT
Where NAMEOFSCRIPT is the filename of your script.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Thanks ToZ, it did not bring up anything...I'm not an expert on this. I looked in "logs", can't see anything about "trash.sh"
Last edited by agashamu (2022-07-07 22:04:12)
Linux Mint Xfce 21.1
Offline
When you say "stops working", do you mean the script has crashed (no longer active) or the sounds just stopped (but the script is still running)?
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
I guess the script is just not starting anymore. Crashed??? I don't know...we could say it's no longer active, there is no sound what so ever. I just wonder why it happens after some time the computer is running. I think (but not 100% sure) if I empty trash every 30-40 minutes or so, then it keeps working. Strange...
Linux Mint Xfce 21.1
Offline
When it stops working, what does the following return?
ps -ef | grep -i trash.sh
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
When it stops working, what does the following return?
ps -ef | grep -i trash.sh
It returns:
ps -ef | grep -i trash.sh
shamu 3687 3546 0 15:33 ? 00:00:01 /bin/bash /home/shamu/bin/trash.sh
shamu 16304 16226 0 15:55 pts/0 00:00:00 grep -i trash.sh
Linux Mint Xfce 21.1
Offline
Okay, so the script is still running but the sound stops. Does the sound work elsewhere? Maybe the sound server has crashed?
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
If I click on the sound file it plays with Clementine. With "play" command, it plays in the terminal, I believe "play" is Sox. The file is in /usr/share/sounds/, maybe it should be in /home/.config/sounds/? It's a .wav file, should it be .ogg? I have no idea...can it be the sound card? It's very old. However, all other sounds work fine.
Last edited by agashamu (2022-07-09 00:56:08)
Linux Mint Xfce 21.1
Offline
Try this. In a terminal window run this command:
sleep 1 && ls -l ~/.local/share/Trash/files | wc -l
This will start a counter running which is basically the number of entries in the trash directory.
Test 1: delete a file. The counter should increase by one
Test 2: empty the trash. The counter should decrease by the number of files deleted.
Now when you run into the problem when the trash sounds stops, run this script again. Delete a file. Then empty the trash. See if the numbers change at all.
Also, when the sound is no longer working, post back the results of:
ls -l ~/.local/share/Trash/files
...and:
gio info Trash://
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Here is another option. It uses inotifywait to watch for changes - in this case file deletions in a directory and plays the sound. You need to install the inotify-tools package for this script to work. It may be more reliable than the other script:
#!/bin/bash
# requires inotify-tools
DIR="$HOME/.local/share/Trash/files"
# make sure that only one instance of this script is running per user
lockfile=/tmp/.trashsound.$USER.lockfile
if ( set -o noclobber; echo "locked" > "$lockfile") 2> /dev/null; then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
echo "trashsoundDEBUG: Locking succeeded" >&2
inotifywait -q -m -r -e delete $DIR | while read D E F; do
mplayer /home/yourusername/Sounds/trash.mp3
done
# can't create lockfile - notify user and quit
else
echo "trashsoundDEBUG: Lock failed, check for existing process and/or lock file and delete - exiting." >&2
exit 1
fi
You'll need to edit the line that points to your sound file.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Thank you ToZ for spending so much time on this "not-at-all-life-threatening" issue. To me it became more like a curiosity to find out why the system does what it does. I will be busy working on it now. Thanks again!
Linux Mint Xfce 21.1
Offline
[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 655.29 KiB (Peak: 688.13 KiB) ]