How To: Add a Script/AppImage/Executable as an Icon in the GUI

One of the biggest UX productivity boosts that you can do is to add an icon to the Raspberry Pi Main Menu or to the desktop which will launch an executable or a script, doubly so when you have a device which doesn’t have a full-sized screen and full-sized keyboard and mouse. Typically when you install software from the “Add / Remove Software” tool or through the use of apt, if the software has a GUI, then this icon is done for you. However, wouldn’t it be awesome to do the same thing for software which doesn’t do this automatically or custom scripts that you’ve created? Here’s how you do it very easily. This process starts off assuming that you’ve already downloaded or created functioning software. If you’re code isn’t working, then this process isn’t going to help much. :wink:

For the sake of this tutorial, we’re going to call our ficticious software clockwork-demo-tool.

Create the .desktop File

  1. cd /usr/share/applications. This is where you’re going to store all of your custom .desktop files. if you do a quick directory list (ls) here you’ll see that there are a ton of them here. While you can easily copy one of those and makd e changes, often you’ll end up copying more than you need.

  2. sudo nano clockwork-demo-tool.desktop: Using your favorite command line editor (I’m going to use nano here but you can just as easily use vi or pico) create the desktop file. You can name it anything that you want, but I tend to prefer to name it the same as the app itself (or something as close to it as possible).

  3. Add the following to your new .desktop file:
    [Desktop Entry]
    Name=Clockwork Demo Tool
    Comment=This is our Demo
    Type=Application
    Exec=/PATH/TO/EXECUTABLE
    Icon=/usr/share/icons/Custom/clockwork-demo-tool.png
    Categories=Utility;
    Terminal=False;

    Each of the lines above correspond to something required for the file. I can briefly explain:

    1. [Desktop Entry] – required for the creation of a .desktop filie.
    2. Name – This is what shows up in the Raspberry Pi Main Menu, launch tool or hover when the icon is interacted with.
    3. Comment – Not necessarily a “comment” per se, but more so explanitory text. If you use something like synapse then this additional context can be helpful.
    4. Type – This directive takes one of three values: Application, Link, or Directory. I’ve always just left it alone as Application.
    5. Exec – This is important. This is an absolute path to your executable along with any flags that may be required to launch that executable the way that you need to launch it (i.e. in sandbox mode for example).
    6. Icon – I like to create a directory called Custom in the icons directory to store all of my custom icons, though you can literally use any icon that you wish.
    7. Categories – This organizes the application in the Raspberry Pi Main Menu. “What Categories can you choose from,” you ask? Here you go: Registered Categories | Desktop Menu Specification .
    8. Terminal – This determines whether or not the Terminal GUI launches when the Exec path is run. Typically, unless you need to see output, I’d leave it as False.
  4. Once done, save that file and you’re good to go.

Download the Icon

Find the icon for the software that you are creating the .desktop file for and safe it to /usr/share/icons/Custom/clockwork-demo-tool.png. Keep in mind that if /usr/share/icons/Custom doesn’t exist in your device, you’ll have to create it or come up with another location to save your apps.

That’s it!

It’s really that simple. If you set up your Categories correctly, then the icon should show up within a few seconds. If you’re adding it to your Desktop, then you should be able to add it as usual. I have used this process in the past to run a shell script which sets up Monitor Mode when a specific antenna is plugged in. This is really helpful for quickly running commands where the lack of a full-sized keyboard is a huge problem.