How to create an Ubuntu desktop entry to run Jupyter

Here's how you can create a Gnome desktop entry shortcut launcher icon to start up Docker and open Jupyter so you can start working faster.

How to create an Ubuntu desktop entry to run Jupyter
Picture by Practical Data Science.
3 minutes to read

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.

1. Create your command

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'

2. Find an icon

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.

3. Create a desktop entry

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]
Exec=gnome-terminal -x sh -c 'docker start tensorflow_notebook;google-chrome'

4. Restart Gnome

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.

Desktop entry

Matt Clarke, Sunday, March 07, 2021

Matt Clarke Matt is an Ecommerce and Marketing Director who uses data science to help in his work. Matt has a Master's degree in Internet Retailing (plus two other Master's degrees in different fields) and specialises in the technical side of ecommerce and marketing.