You are not logged in.
Pages: 1
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
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
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
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
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
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
If you can reproduce it or figure out which version/setup it used to work with please let us know.
Offline
I now created my own patch to achieve this, see https://gitlab.xfce.org/xfce/thunar/-/issues/343
Offline
Pages: 1
[ Generated in 0.013 seconds, 7 queries executed - Memory usage: 548.47 KiB (Peak: 549.31 KiB) ]