Add Trash Can to Left Panel (Dock Launcher) in Ubuntu 18.04

Last updated: August 30, 2018

gnome shell

While the trash icon does not have ‘Add to Favorites‘ context menu option, here’s how to manually add a trash can icon to the left launcher in Ubuntu 18.04 Gnome Shell.

First see the result effect (in the picture, the left panel was replaced by Dash to Dock extension):

1. Open terminal either via Ctrl+Alt+T shortcut key, or by searching for ‘terminal’ from app launcher.

2. Run command to create and edit an empty file called trash.sh:

gedit ~/Documents/trash.sh

When the file opens, paste following lines and save it.

#!/bin/bash
icon=$HOME/.local/share/applications/trash.desktop

while getopts "red" opt; do
	case $opt in
    r)
	if [ "$(gio list trash://)" ]; then
		echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash-full\nExec=nautilus trash://\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec='$HOME/Documents/trash.sh -e'\n' > $icon
	fi
	;;
    e)
	gio trash --empty && echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash\nExec=nautilus trash://\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec='$HOME/Documents/trash.sh -e'\n' > $icon
	;;
    d)
	while sleep 5; do ($HOME/Documents/trash.sh -r &) ; done
	;;
  esac
done

3. Make the script file executable and run it via the 2 commands:

chmod +x ~/Documents/trash.sh

./Documents/trash.sh -e

4. Search for ‘trash’ in software launcher and select ‘Add to Favorites’ in its context menu.

5. Finally open Startup Applications, click Add to add a new startup app:

  • Type a name for the trash script.
  • Type command /home/YOUR_USER_NAME/Documents/trash.sh -d

Reboot Ubuntu, and the trash can icon will change when it’s empty or not empty.

via: ubuntuforums

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

6 responses to Add Trash Can to Left Panel (Dock Launcher) in Ubuntu 18.04

  1. Carlos Henrique August 30, 2018 at 9:38 pm

    Ji I did the translation here for my language (Brazilian) and it was perfect.
    Congratulations

  2. Thanks you for tutorial, but can we replace the “show applications” button to Trash?

    • That’s not easy as “show applications” button is hard coded. Try Dash to Panel or Dash to Dock extension (both available in Ubuntu Software) to replace the left panel if you don’t like the button postion.

  3. or you can use that :

    native Trash gnome shell extension :

    https://extensions.gnome.org/extension/48/trash/

  4. Thanks a lot