1

Is there any way to add a sound event every time I empty the trash on my Ubuntu system?

6
  • 1
    In Ubuntu 13.04 there is a sound as a hammer blow (that scares me sometimes) that it's warning me about what I intend to do. Also, a warning window appear in this sense. You don't have this behavior? Aug 24, 2013 at 9:33
  • no @RaduRădeanu i am using ubuntu 12.04 lts, and i don't have such behavior. any idea how i might add that event ( read as : even i want to get scared sometimes :P :P ) Aug 25, 2013 at 8:36
  • 1
    i too dont have this behaviour @RaduRădeanu , even no login sounds nothing except drumming one at the start, most of my friends dont have those sounds but some have ..
    – Sukupa91
    Dec 4, 2013 at 16:42
  • 1
    @Sushantp606 if you want startup sound, imho i can help you with that and can show you how to add that up. so that it can play on every login. Dec 4, 2013 at 17:20
  • @KunalSangwan i knew that for login , but if its about everything like logout,shutdown, events , caution and please do tell me..
    – Sukupa91
    Dec 4, 2013 at 17:22

3 Answers 3

4

Empty Trash Sound Workaround

for Ubuntu 12.04.3

Maybe you will find my idea useful. After 2 months of searching for a solution to get a trash-empty sound in Ubuntu 12.04.3 I finally was able to put together something that works for me. If anyone has an improved solution then please share.

You will note in the script below that I have chosen to use the "music123" app which can be downloaded from the Ubuntu Software Centre and installed to the /usr/bin folder. I got the idea from an article on how to set up Ubuntu shutdown sound --> from here.
That one worked great also, 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 which was also downloaded from the Ubuntu Software Centre.

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"
trash-list > ~/.local/share/Trash/files/trash.lst
file = ~/.local/share/Trash/files/trash.lst

if [ ! -s $file ]; then

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

else

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

           case $? in

                0)
                trash-empty;
                /usr/bin/music123 $SOUND
                ;;

           esac

fi 

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.

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

                                      ~.~

You can make an "Empty Trash" launcher and put it on your desktop to launch this script whenever you want to empty the trash. Make sure that you have made this script executable. "Empty Trash" desktop script launcher

Attach a unique icon to the launcher. This is the one I used: "Empty Trash" icon for the desktop script launcher

This is the Zenity dialogue question box to confirm emptying of trash: Empty Trash confirmation zenity question box

This is the Zenity dialogue info box that appears if the trash bin is empty and you have clicked on the "Empty-Trash" launcher.

Zenity empty trash info box

I added the above edit to provide the images that were not permitted during my initial post. I hope this extra information is useful. - walt -wladicus 2013.12.30

2
  • 1
    You are welcome ASCIIbetical. I am happy that my little bit of research not only worked for me, but has found a hopeful application for someone else. -walt
    – wladicus
    Dec 29, 2013 at 16:55
  • FYI - This script throws some errors for me on 14.04 LTS
    – Elder Geek
    Jan 31, 2016 at 0:08
2

For Ubuntu 14.04 and beyond I modified the script by wladicus that I found here to eliminate the errors I was getting due to some unwanted spaces and program flow and made some other minor customizations to insure dependencies are satisfied. You'll need to choose your own sound file and replace /usr/share/sounds/ubuntu/stereo/GarbageTruckSounds.ogg on the SOUND= line below as that sound is no longer included with Ubuntu.

#!/bin/bash
# Name of script: empty-trash.sh
# script to empty trash with confirmation and empty trash sound event
# This script can be stored in /usr/local/bin or wherever you keep your scripts
# original script created trash.lst in the trash and so never reported "trash is empty"
# modified script to create trash.lst elsewhere and only remove it if the trash was to be emptied.
# utilized mplayer to play the sound rather than the original program as I didn't see the need to install another program.
# I also removed some spaces that were causing the script to throw errors and added a function to get dependencies as required.
function get_dependency
{
   exist="$(dpkg-query -l | grep "ii $@")"
   if [ "$exist" == "" ];
    then echo "$@ is required and not found. Attempt install Y/N"
    read -n 1 solve
    if [ $solve=={Yy} ]
    then sudo apt -y install "$@"
    else echo "Cannot continue as $@ is required."
    exit 1
    fi
    fi
}
get_dependency zenit? #full name zenity on this line caused issues. Used globbing to avoid this.
get_dependency trash-cli
get_dependency mplayer
 SOUND=/usr/share/sounds/ubuntu/stereo/GarbageTruckSounds.ogg
trash-list > ~/.local/share/trash.lst
file=~/.local/share/trash.lst

if [ ! -s $file ]; then
        zenity --info --text "TRASH is EMPTY"

else

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

           case $? in

                0)
        rm $file;
                trash-empty;
                mplayer "$SOUND"
        ;;

           esac

fi

Note that this script requires zenity trash-cli and mplayer If they don't exist the script will attempt to install them. Packages with a dpkg status of rc (removed but configuration files remain) will fail to be reinstalled. I noticed this anomaly in testing with the mplayer package. If you have this issue you can resolve it by removing the configuration files of the offending package with the command sudo apt purge [packagename] which in my case was sudo apt purge mplayer

Also note that 2 of these packages reside in the universe repository and installation of dependancy installation will fail if you don't enable the universe repository first.

2
  • Stumbled across this awesome script purely by accident! Feb 17, 2021 at 23:41
  • @WinEunuuchs2Unix I'm pleased you like it!
    – Elder Geek
    Feb 19, 2021 at 12:47
0

First run "sudo apt-get install mpg123" to play the mp3 files.

Then I created a shell script called "/home/yourname/scripts/check_trash.sh"

#!/bin/bash 
cd /home/yourname/.local/share/Trash/files
while true
do
   TOT1="$(ls -1 | wc -l)"
   sleep 2
   TOT2="$(ls -1 | wc -l)"
   if [ "$TOT1" != "$TOT2" ];
   then
     mpg123 -q /home/yourname/trash.mp3 
  fi
done

then download a mp3 file and copy it to "/home/yourname/trash.mp3"

Then add the program "/home/yourname/scripts/check_trash.sh" so it runs on bootup: https://www.howtogeek.com/103640/how-to-make-programs-start-automatically-in-linux-mint-12/

2
  • 1
    Mint is not an official Ubuntu variant, so off-topic here. Better copy-paste the instructions over from the link to here if you can test on Ubuntu.
    – Fabby
    Feb 12, 2019 at 22:21
  • That's a neat workaround. If one wanted they could use the inotifywait command instead. Feb 13, 2019 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.