2013-12-22

Empty Trash Sound Workaround
for Ubuntu 12.04.3 
=============================================================
After 2 months of searching for a solution to get a trash-empty sound
in Ubuntu 12.04.3 a work-around solution, that works for me, became evident.
Maybe you will find it useful. If anyone has an improved solution then please share.

You will note in the script below that the "music123" app app was used.  
This application can be downloaded from the Ubuntu Software Centre. 
In my case it was downloaded and installed to the /usr/bin folder as described 
in an article on adding a shutdown sound to Ubuntu --> from here.  
That one worked great, and I even added the Ubuntu start-up sound.

The following script also uses the commands "trash-empty" and "trash-list".
These commands are part of the "trash-cli" command line utility.
The "trash-cli" app was downloaded from the Ubuntu Software Centre
and installed so that the script below could use the "trash-list" command to
check if there was trash to be emptied, and the "trash-empty" command
to actually empty the trash in all accessible trash bins.
=============================================================
1. Make the sound file (glass breaking sound was my choice)
    and called the file “trash-empty.ogg”. If you use the music123 app
    then any of the following audio file types can be used:
    .wav  .ogg   .oga   .mp3  (and maybe others-I have not checked).

         2. Next make a desktop launcher icon.

Give the launcher an appropriate name such as “empty-trash+sound.png”.

    3. The Following Script is launched from the desktop launcher:


 ------------------------------------------------------------------------------------------------------------------------------------

Linux Script to Empty Trash with sound of glass breaking. 

#!/bin/bash
#
# Name of script: empty-trash.sh
# script to empty trash with confirmation and empty trash sound event
# This script is located in /usr/local/bin

SOUND = "/usr/share/sounds/ubuntu/stereo/trash-empty.ogg"  # location of trash-empty sound file
trash-list > ~/.local/share/Trash/files/trash.lst  # list all trash in file "trash.lst"
file = ~/.local/share/Trash/files/trash.lst  # location of trash list file

if [ ! -s $file ]; then    # if the "trash.lst" file is empty

        rm -f $file;
        zenity --info --text "TRASH is EMPTY"

else                           # if the "trash.lst" file is not empty


        zenity --question --title "Confirm Yes/No" --text "EMPTY Trash Bin ?"

           case $? in       # Check whether user clicks on "Yes" or "No"
                0)
                trash-empty   # user asked for trash to be emptied
                /usr/bin/music123 $SOUND  # play trash-empty sound file
                ;;
           esac
fi 

------------------------------------------------------------------------------------------------------------------------------------
  4.  Make the script executable.
  5.  Create a launcher for this script. 


  6.  Add this launcher app to the top panel or wherever you like to have it.   I put it in the bottom panel.


If you have a trash bin on the desktop or elsewhere, it will continue to work properly and it will still show the full and empty trash bin icons. If you do not want to hear the trash-empty sound then you can right-click on your regular trash bin icon and empty the trash in the usual way.

To empty the trash and hear your chosen sound click on the launcher made for that purpose.  My trash-empty sound is that of breaking glass. You can choose whatever sound file you like, or make your own.


Here are the pictures of the dialogue pop-ups generated by zenity in the above script:

If the trash bin is full then the above confirmation dialogue appears.

If you click on "Yes" all the trash in all locations, including partitions and USB drives, will be emptied.

If the trash bin is empty (in all locations) then the above information dialogue appears.


~.~


joy,
walt