Tuesday, March 24, 2020

How to create desktop program launchers in Linux

I've seen some people, like myself, that tend to create shortcut keys for their favorite programs. For others, with only a few favorites, they'll create panel shortcuts. For others, however, they literally litter their desktop with a slew of icons, much like they might for their smart phone.

This tendency probably occurs because when Windows first came out, nearly every program you installed in it would pop in what was called a desktop "shortcut." They called it that because it was a shortcut in contrast to going through the menu to start it. In LInux, they are called "launchers," because, well, they launch programs.

Programs in LInux systems, however, rarely do that, which is why you'll usually see Linux desktops with hardly any icons. Usually just the Computer file system, the home directory of the user, and often any mounted drives like a CD or USB drive.

As with most things in Linux, there are several ways to skin this cat, and which option will work for you depends upon which desktop GUI (Graphical User Interface) you are using.

For example, I use a Cinnamon desktop GUI. The easiest way to create desktop launchers of your most used programs is to use the menu to browse until you've found the program you want to use. Alternately, you can use the search function at the top to easily find any program. Then right-click on the program and select "Add to Desktop" from the pop-up menu. If you try that in whatever GUI you are working in and that option isn't there, never fear. There are other options.

Also, the following method can be used for command-line programs for which there are not graphical interfaces at your ready, like the text-based editor: nano.

In Cinnamon, and other GUIs, you can often right-click on an open spot on your desktop.  There you will see in the pop-up menu, one choice that says, "Create New Launcher Here..." GUIs other than Cinnamon will likely have similar wording. If not, there is still yet another option which I will go through in a minute.

What pops up in Cinnamon looks like this:


Different GUIs will likely have similar fields. First, you will likely want to change the icon to one more resembling the program you are about to enter. To do that, click on the icon above, which resembles a rocket. You can browse or search your options there to select one.

Then you'll want to give your program a name, like "Silly Windows clone of Explorer" Whatever you type there will be displayed below the icon on your desktop.

Next, you'll fill in the command-line part of the program. This is the command you would type into the terminal on a command-line, with an appropriate place holder for any file that would tend to go with it.  Since the default is to include any file after it, there is no need for a place holder for LibreOffice Writer.

For instance, if you wanted to create one for LibreOffice Writer, the command would be lowriter  or libreoffice --writer

Don't know the command-line version of a program? Here's how you find it. Open the terminal (Ctl-Alt-t) and enter the following: man (progam name)  It will then display a "manual page" for the program. Look under the "Synopsis" section, and it will tell you the command to run it, and further on it should tell you if it needs a parameter to use any files passed to it. Another option is to enter in the terminal: libreoffice -h or --help. That will give you a shorter listing of the command-line entry, but man is more complete and you have a chance to see the beginning without having to scroll back up if the help info is larger than a page.

So, if you entered "man libreoffice", you would get an extended help file listing out the things to know. You can also enter "info (your program) to get a cleaner Synopsis information.

Going back to entering the info in our launcher window, the next field is the Comment section. This is a "what this program does" spot and will show up whenever someone hovers over the icon. Something like "A cool word processor"

The next entry is whether or not to click the box next to "Launch in Terminal." You'll want to click it if it is going to run a command-line only program, like nano. Otherwise, you'll want to leave it unchecked.

For instance, let's say you wanted to have a desktop entry that would check if any of your programs from your repositories needed upgrading. You would create a launcher with the name of "Update check," then the command: sudo apt list --upgradable, a comment that says "Check to see if any upgrades need to be done," then click the box that says to Launch in Terminal.  Once you hit OK, it will put an icon on the desktop that will launch the apt program, and after verifying your credentials, it will give you a list of all upgradable programs in the terminal window.

Once you hit OK, it will then give you the option to put it in the menu as well. Just say nope or you can click it and follow the instructions for it to preform that function.

So, you don't have either function, how do you accomplish that ability?

For this option, you'll be creating and editing a desktop file.

Where are these files? For systemwide icons for everyone who might log in, put the desktop files in /usr/share/applications (you'll need root usr privilege). For each logged in person, you can put the files into their home directory: /home/$USER/.local/share/applications or /home/$USER/Desktop on Cinnamon.

The simplest way to accomplish this is to copy a file and paste it right back, then edit the new file to reflect the new information, paying attention especially to the name, exec, and comment sections. You can change the terminal to true if you need it. Don't forget to rename the file itself to (whatever you want to call it).desktop   

You can create the file from scratch. Before you do that, it would be a good idea to check this more detailed article on what to enter.

There you go. Another reason why I like Linux Mint Cinnamon, it makes it real easy to do what would be a more manual and not user friendly functions.

No comments:

Post a Comment