Adding a Directory Shortcut to the Dash Panel In Ubuntu

Published: 2023 August 31

system administration Linux Ubuntu GNOME

Background

Several Linux distributions use the GNOME desktop environment. For Ubuntu, which we’ll focus on here, this is true for the “vanilla” (i.e. the “standard”, “stock”, or “base”) Ubuntu distribution, as well as several “flavors” of Ubuntu.

One of the main elements of the GNOME desktop is the dash panel or dash bar, which GNOME refers to as the dash: “The dash shows you your favorite and running applications." (I think referring to it as “the dash” is a little cryptic to newcomers so in this post I’ll refer to it as the dash panel instead.) The dash panel offers a simple way to launch and access applications.

Objective

It’s straightforward to add an installed application to the dash panel in Ubuntu. You simply:

  1. open the application,
  2. right click on it’s icon in the dash panel, and
  3. click Add to Favorites.

Adding a shortcut to the dash panel pointing to a specific directory requires a little more work.

Let’s say we have a directory that we want to easily access from the dash panel. In this post we’ll create a shortcut to launch it.

Solution

The general approach and some helpful technical background of the solution for creating desktop entries are outlined in this StackExchange answer, but we’ll make a few modifications for our situation.

For this example we’ll say we want

Adding the icon

We’ll start by placing the icon in a directory where GNOME will find it.

We’ll create a distinct directory called zzz-mine so that we know where to find this and other icons we might add in the future. We’ll need superuser privileges to modify things in this directory, so we’ll prepend the command with the sudo command. (If you’re not familiar with the sudo command, you should learn more about some of it’s uses and hazards.)

sudo mkdir /usr/share/icons/zzz-mine/

Then we’ll move our icon into that folder. This too will require superuser privileges, so we’ll again use the sudo command.

sudo cp /home/Bob/icons/brilliant-sunrise.png /usr/share/icons/zzz-mine/brilliant-sunrise.png

After confirming that our icon is copied into the new folder, we’re ready to proceed.

Confirm name availability

Next, we’ll confirm that there isn’t an existing desktop entry with the desired name.

Confirm desired shortcut name is available

First, we can test for it by pressing the Super key and then typing the desired name.

[Super] ProjectX

If nothing comes up, that’s a good sign that the shortcut name is available. If an exact match does come up, select a different name for the shortcut.

Confirm filename is available

Second, we’ll navigate to the directory where we’ll make our new entry to confirm that our intended filename isn’t in use there.

cd ~/.local/share/applications/
ls *.desktop

If you dont see a ProjectX.desktop file, than you’re fine to proceed. If you do, you’ll need to choose a different filename.

Create the desktop entry file

Since we confirmed that the name is available we can now create our new .desktop file.

touch ~/.local/share/applications/ProjectX.desktop

We’ll next populate it with the necessary information. We’ll open the file.

gedit ~/.local/share/applications/ProjectX.desktop

And populate it with the relevant information:

[Desktop Entry]
Name=ProjectX
Exec=nautilus --new-window '/home/Bob/Documents/ProjectX'
Comment=Open ProjectX directory
Icon=/usr/share/icons/zzz-mine/brilliant-sunrise.png
Type=Application

As previously mentioned, this StackExchange answer provides general information for the solution, but here we’ll go over some of the details specific to our case.


Name=ProjectX - Names the shortcut ProjectX.

Exec=nautilus --new-window '/home/Bob/Documents/ProjectX' - Opens a new file manager window to the /home/Bob/Documents/ProjectX directory.

Icon=/usr/share/icons/zzz-mine/brilliant-sunrise.png - Assigns the icon we selected to the shortcut. NOTE: The icon must use the absolute path, not a relative path.


After adding the required text, we can save and close the ProjectX.desktop file.

Save the shortcut as a favorite

Now that we have our desktop entry completed and in the proper folder we can search for it and save it as a favorite:

  1. Press the Super key or click on the “Activities” button.
  2. Search for *ProjectX” by typing it into the search field. Our shortcut should appear with the icon we selected. (If it doesn’t, confirm you saved the desktop file, wait a few moments, and try again. It will likely only take a few seconds.)
  3. Right click on the icon and select “Add to Favorites”.

You should now see your new shortcut on the dash panel.

Click it to confirm that it’s working as expected.

Conclusion

We now have a working shortcut that provides a quick way to access our project files.

Copying Directory Structure With a Bash Script - With Help From ChatGPT AI

Published: 2024 January 22

Setting Up a Raspberry Pi as a Linux Print Server with CUPS

Published: 2024 January 19

Setting Up a Raspberry Pi Zero 2 W with Ubuntu Server

Published: 2024 January 04