Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-12-31 19:11:53

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Empty Trash Can Sound

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!

Offline

#2 2021-12-31 19:42:01

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 8,939

Re: Empty Trash Can Sound

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.

Offline

#3 2021-12-31 21:05:33

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Re: Empty Trash Can Sound

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)

Offline

#4 2021-12-31 21:11:34

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 8,939

Re: Empty Trash Can Sound

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

Offline

#5 2021-12-31 21:39:57

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Re: Empty Trash Can Sound

Yes, I get the sound.

Offline

#6 2021-12-31 22:23:08

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 8,939

Re: Empty Trash Can Sound

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?

Offline

#7 2021-12-31 22:48:32

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Re: Empty Trash Can Sound

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??

Offline

#8 2021-12-31 23:57:55

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 8,939

Re: Empty Trash Can Sound

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)

Offline

#9 2022-01-01 22:39:01

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Re: Empty Trash Can Sound

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)

Offline

#10 2022-01-02 06:02:50

KBar
Moderator
Registered: 2021-11-05
Posts: 444

Re: Empty Trash Can Sound

agashamu wrote:

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? big_smile

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! tongue

Offline

#11 2022-01-02 17:34:19

agashamu
Member
From: California
Registered: 2021-03-01
Posts: 34

Re: Empty Trash Can Sound

Good question, I don't know...
Happy New Year to you Sir!!!

Offline

Board footer

Powered by FluxBB