Despite the massive improvements to usability on Linux over the years, it still remains unnecessarily complicated to create shortcut icons on Gnome.
As of Ubuntu 20.04, there’s still no quick and easy way to create the desktop entry files that allow you to add icons to your applications panel, dock, or launcher, so you can quickly start up an application. Thankfully, it does only take a minute.
Here’s how I created a desktop entry launcher to open Docker, start up my TensorFlow Notebook container and open up Jupyter notebook in my Google Chrome browser.
When you click an icon on your Ubuntu dock or on the applications panel the click executes a command to be run via the command line. Therefore, the first step is to format your launcher command.
Every time I turn on my workstation I run a Docker command to fire up my tensorflow_notebook
Docker container, which in turn starts a Jupyter notebook server on port 8888 of localhost. Then I open Chrome and click a bookmark to the URL.
Here’s a one-liner command that does everything. The gnome-terminal -x sh -c
was essential for running this correctly via the launcher icon.
gnome-terminal -x sh -c 'docker start tensorflow_notebook;google-chrome http://127.0.0.1:8888'
Next you’ll need to find an appropriate icon to use. Transparent PNG icons look best. There are loads of these on Google images. Find one you like and save it to your machine.
Next, open Gedit as a superuser and create a new desktop entry called jupyter.desktop
in the /usr/share/applications
directory. Gnome looks in here and adds the icons to the applications panel of Gnome.
sudo gedit /usr/share/applications/jupyter.desktop
The desktop entry file is just a text file into which you add a series of key=value pairs which tell Gnome what to do when the launcher is clicked. The Exec
rule contains the command that starts Docker and opens Chrome on the Jupyter server page. I’ve placed my jupyter.png
icon in /usr/share/applications
and have set Terminal
to False
and StartupNotify
to True
.
[Desktop Entry]
Encoding=UTF-8
Name=Jupyter
Exec=gnome-terminal -x sh -c 'docker start tensorflow_notebook;google-chrome http://127.0.0.1:8888'
Icon=/usr/share/applications/jupyter.png
Type=Application
Categories=Development;
Terminal=False
StartupNotify=True
Finally, you’ll need to exit Gnome and log back in again. Enter the below command, log back in, and check out the Show Applications panel. You should see your icon and clicking it should fire up your browser.
gnome-session-quit --no-prompt
You can, of course, use the same approach for any scripts or commands you run regularly. The icons can also be dragged from the applications panel to your dock for faster access.
Matt Clarke, Sunday, March 07, 2021