JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

HOW TO - Add an "Empty Trash" option

Wed Feb 17, 2016 3:10 pm

I've added this to 2 different Pi's (B+) running Jessie, no problems. Thanks go to Nicolas Bernaerts for the scripts.

When you right click on the "Trash" icon you'll have "Empty Trash" included in the dropdown menu. When selected it will show the number of items in the trash and ask to confirm deletion. Just like Mother Nature intended.

All the commands/steps are shown below. If you're wary of using wget, and what the files may contain, I'll include the contents at the bottom so you can look them over and manually copy/paste the files to the proper location.

First install "trash-cli"

Code: Select all

sudo apt-get update
sudo apt-get install trash-cli
Now we'll create a couple of new directories. Don't use sudo, these should belong to the user.

Code: Select all

mkdir --parents $HOME/.local/share/file-manager/actions
Next we'll fetch the .desktop file and put it in the new "/file-manager/actions" directory. That's all one long line, don't break it.

Code: Select all

wget -O $HOME/.local/share/file-manager/actions/ask-trash-empty.desktop https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/lubuntu/trash-empty/ask-trash-empty.desktop
We need to add a shell script to "/usr/local/bin" and make it executable. You'll need sudo for this.

Code: Select all

sudo wget -O /usr/local/bin/ask-trash-empty https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/lubuntu/trash-empty/ask-trash-empty

sudo chmod +x /usr/local/bin/ask-trash-empty
Now log out then back in, or reboot. Right clicking on the Trash icon should now provide an "Empty Trash" option.

________________________________________________

If you prefer to do it manually rather than using "wget":

Contents of "ask-trash-empty.desktop". Put it in "~/.local/share/file-manager/actions".

Code: Select all

[Desktop Entry]
Type=Action
Profiles=profile-zero;
Name[en_US]=Empty Trash
Name[en]=Empty Trash
Name[C]=Empty Trash
Name[fr_FR]=Vider la corbeille
     
[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Basenames=trash:///
Exec=/usr/local/bin/ask-trash-empty
Name[en_US]=Empty Trash
Name[en]=Empty Trash
Name[C]=Empty Trash
Name[fr_FR]=Vider la corbeille
Contents of "ask-empty-trash". Put it in "/user/local/bin". Don't forget to make it executable.

Code: Select all

#!/bin/sh
# -------------------------------------------------------
#  Script used to empty trash from context menu 
#
#  Used in http://bernaerts.dyndns.org/linux/...
#
#  01/11/2014, V1.0 - Creation by N. Bernaerts
# -------------------------------------------------------
 
# retrieve number of files in the trash
TRASH_QTY=`/usr/bin/trash-list | wc -l`
 
# ask for confirmation
[ "$TRASH_QTY" != "0" ] && zenity --question --title="" --text="Trash contains $TRASH_QTY items.\n\nDo you want to empty it ?"
 
# if answer is yes, empty trash
[ "$?" = "0" ] && /usr/bin/trash-empty

Dewsweeper
Posts: 1
Joined: Mon May 09, 2016 3:14 pm

Re: HOW TO - Add an "Empty Trash" option

Mon May 09, 2016 3:40 pm

While the CLI commands work to add 'Empty Trash' to the right click menu, My question is "Why isn't this the default setup?" This is the way most operating systems are configured and, in my humble opinion, is a significant burden for a new user.

alotibwk
Posts: 2
Joined: Fri Mar 31, 2017 4:01 pm

Re: HOW TO - Add an "Empty Trash" option

Fri Mar 31, 2017 4:09 pm

:" now the wastebasket unvisible
i just copy and paste the command line then reboot the system :roll:
I tried to use empty-trash code but not work. Also i see wastebasket in Desktop appearance settings and check on it. and still not visible in the desktop
i want autoremove wastebasket

alotibwk
Posts: 2
Joined: Fri Mar 31, 2017 4:01 pm

Re: HOW TO - Add an "Empty Trash" option

Sat Apr 01, 2017 6:09 pm

I reboot the system again and i see the new option Empty "Trash" and the wastebasket visible in the desktop

hope rpi put this option in the next update of raspbian

salam

Return to “Advanced users”