Xfce Forum

Sub domains
 

You are not logged in.

#1 2024-08-31 22:02:24

gschwarz
Member
Registered: 2023-03-30
Posts: 23

Play a sound when trash is being emptied

I am looking for a solution which will play a sound when the trash is being emptied.
I came across this issue, and it looks like there is no support (e.g appropriate hooks one could use) built-in from XFCE for that functionality, is there?
https://gitlab.xfce.org/xfce/thunar/-/issues/343

So the only chance is to run a process which constantly montors the number of files in the trash changing to 0?
I used this thread as an inspiration
https://forum.xfce.org/viewtopic.php?id=15505

and created the following script:

#!/bin/bash
while true
do
while [ $(gio trash --list | wc -l ) -eq 0 ]
do
    sleep 1
done
while [ $(gio trash --list | wc -l ) -gt 0 ]
do
    sleep 1
done
canberra-gtk-play -i trash-empty
done

I added it as a startup item so it's launched on login.
It does the trick, but of course with some minor delay.

I'm wondering if this can be done any better, also in terms of resource usage. Is there a way not to actively constantly poll the number of files but somehow to be notified by the system when the trash gets emptied? I'm afraid no, but maybe there is.

Is there a more efficient way to determine whether or not the trash is empty than  $(gio trash --list | wc -l )?

gio also has an info feature which can be used on trash:// and which has an attribute trash::item-count. Is there an elegant way to read it short of parsing the multi-line text output?

Last question, more a cosmetic one: what is the appropriate place to put such a script (in the user's home directory)? Is there a "generic" place to put such local/personal scripts/applications?

Last edited by gschwarz (2024-08-31 22:06:04)

Offline

#2 2024-08-31 22:34:50

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

Re: Play a sound when trash is being emptied

The optimal way would be to code thunar to do it. The script is a workaround, but its not without a penalty. What if you just enabled system sounds? Most sound themes have a "trash-empty" sound and it is supported by GTK (via libcanberra).

Last question, more a cosmetic one: what is the appropriate place to put such a script (in the user's home directory)? Is there a "generic" place to put such local/personal scripts/applications?

There doesn't seem to be any official standard that I have come across. Personally, I use ~/bin, but you have to make sure it is added to your PATH. The other location I see referenced more frequently is ~/.local/bin.

Edit: the other option is to use inotifywait, but I'm not sure of that would be significantly less cup intensive.

Last edited by ToZ (2024-08-31 22:36:59)


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 2024-08-31 22:51:30

gschwarz
Member
Registered: 2023-03-30
Posts: 23

Re: Play a sound when trash is being emptied

Well, I am using that trash-empty sound, but it looks like XFCE does not support playing it automatically when the trash gets emptied (which of course is what I am looking for). See issue 343 I linked above.
I'd be glad to be wrong on that.

Worrying about the path is not necessary since I am specifying the location with XFCE's startup items setup.

Sadly, I just hit a limitation of my script's approach:

when I manually drag (the only) item out of the trash, the trash empty sound is (of course) being played, which is not intended and super annoying from a UI perspective.

Offline

#4 2024-09-01 12:17:08

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

Re: Play a sound when trash is being emptied

So interestingly, I just played around with libcanberra sounds again and I can't get the trash-empty sound to wok anymore. I was certain it worked before, but the source indicates that it was never supported.

The problem that you are running into is that any of these scripts can only monitor where files exist in the trash or not - they have no way of knowing whether the file was permanently deleted or restored. Only the application itself would be able to control this.


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 2024-09-01 16:42:16

gschwarz
Member
Registered: 2023-03-30
Posts: 23

Re: Play a sound when trash is being emptied

Of course , and that's why the application or the system ("system" being XFCE or some underlying framework in this case) function called to empty the trash should include the option to play a sound.

What do you mean by "I can't get the trash-empty sound to work"? canberra-gtk-play -i trash-empty does work, doesn't it?

Offline

#6 2024-09-01 19:54:16

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

Re: Play a sound when trash is being emptied

Sorry, I meant I don't hear it when I empty the trash from within thunar - I do hear it with the canberra-gtk-play command. I swear it worked before.


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 2024-09-01 19:57:03

gschwarz
Member
Registered: 2023-03-30
Posts: 23

Re: Play a sound when trash is being emptied

If you can reproduce it or figure out which version/setup it used to work with please let us know.

Offline

#8 2024-09-15 19:57:41

gschwarz
Member
Registered: 2023-03-30
Posts: 23

Re: Play a sound when trash is being emptied

I now created my own patch to achieve this, see https://gitlab.xfce.org/xfce/thunar/-/issues/343

Offline

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.010 seconds, 7 queries executed - Memory usage: 544.8 KiB (Peak: 545.64 KiB) ]