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: 136

Empty Trash Can Sound[solved]

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

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

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

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

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

Re: Empty Trash Can Sound[solved]

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

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

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

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

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

Re: Empty Trash Can Sound[solved]

Yes, I get the sound.


Linux Mint Xfce 21.1

Offline

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

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

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

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

Re: Empty Trash Can Sound[solved]

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

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

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

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

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

Re: Empty Trash Can Sound[solved]

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

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

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Empty Trash Can Sound[solved]

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: 136

Re: Empty Trash Can Sound[solved]

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


Linux Mint Xfce 21.1

Offline

#12 2022-07-07 18:49:19

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

Re: Empty Trash Can Sound[solved]

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

#13 2022-07-07 19:06:37

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

agashamu wrote:

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

#14 2022-07-07 19:21:05

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

Re: Empty Trash Can Sound[solved]

Thanks ToZ, is there an "easy way" to bring up the logs/journal report on that script?


Linux Mint Xfce 21.1

Offline

#15 2022-07-07 21:33:53

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#16 2022-07-07 21:38:03

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

Re: Empty Trash Can Sound[solved]

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

#17 2022-07-07 23:23:18

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#18 2022-07-07 23:41:23

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

Re: Empty Trash Can Sound[solved]

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

#19 2022-07-07 23:43:54

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#20 2022-07-08 23:02:07

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

Re: Empty Trash Can Sound[solved]

ToZ wrote:

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

#21 2022-07-09 00:35:58

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#22 2022-07-09 00:52:03

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

Re: Empty Trash Can Sound[solved]

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

#23 2022-07-09 01:26:01

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#24 2022-07-09 01:48:23

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Empty Trash Can Sound[solved]

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

#25 2022-07-09 02:02:06

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

Re: Empty Trash Can Sound[solved]

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

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 655.29 KiB (Peak: 688.13 KiB) ]