Friday, January 10, 2020

Create Desktop Shortcut Ubuntu 19.10

I'm running Ubuntu 19.10 in a Virtualbox and wanted to create desktop shortcuts to programs so that I can quickly launching them (my machine is still running 16.04 since I skipped 18.04 because of Gnome Desktop).

It shouldn't be this much of a pain to create a desktop shortcut but the Gnome Desktop people think the desktop should be nothing more than a Theme Machine.  The Gnome Desktop looks and acts so much like an Apple Ipad I see Steve Jobs ghost every time I look at it.   Alright enough whining from me it's what we got so let's try to make it work for us our way.

First we need to install Gnome Tweaks.  In Terminal (Command Line) type the following:

sudo apt-get install gnome-tweaks

Once it installs, run it. Now navigate to the EXTENSIONS section and turn on the DESKTOP ICONS option.


That's all you need for Desktop Shortcuts but there are other niceties that Gnome Tweaks offers and it's worth looking over later.

To make our desktop shortcut we need to locate the "launcher" file for our chosen program. These "launcher" files are stored in a couple of locations on Ubuntu systems and they have the extension ".desktop" The ".desktop" files are located in the following two directories:

/usr/share/applications/
/home/YOURUSERNAME/.local/share/applications/

*** replace YOURUSERNAME with your logon name (user name)
*** most ".desktop" files are stored in the first location

To get to the ".desktop" files just launch the FILES program and navigate to one of the two folders where the .desktop files are stored.  (NOTE:  to get to the "/usr/share/applications" you will have to first click on the OTHER LOCATIONS option in the left hand column in FILES)


After Clicking on the OTHER LOCATIONS options you click on the COMPUTER option in the left top section of the FILES program.  After that just navigate to the "/usr/share/applications" folder and find the ".desktop" file for the program you want to create a desktop shortcut for.



Below is where ".desktop' files are stored in your home directory.
They are in a hidden folder so you have to check 
the "Show Hidden" option in FILES

Once you've found the ".desktop" file for your desired program you simple Right Click on it and select COPY.  Then navigate to the DESKTOP directory (left side panel in your FILES program) and PASTE your ".desktop" file into the DESKTOP folder.

That will make the ".desktop" file appear on your desktop but the icon will be wrong and it will not function yet. Below you can see that I copied and pasted the ".desktop" file for the program Darktable.  Notice that the "shortcut" looks like a text file and you can see ".desktop" extension still.


To finish make this a usable desktop shortcut you will need to Right Click on the ".desktop" file on your desktop and select properties. Now click on the PERMISSIONS tab and check the "Allow executing file as program" option.  Just closing Properties saves your change (click on the X in the upper right corner).



Okay now the last step.  Once again Right Click on your ".desktop" file on your desktop and you should have an option that says "Allow Launching"  just Left Click on it and it will then be ready and the icon should change to what your use to seeing associated with your program.


You can now double click on your new desktop shortcut and it should start your program.


Wouldn't it be a lot easier to just allow a right click on your desktop and browse to your desired application?  Or even have an GUI app installed by default that did most of the heavy lifting for you?  Well there's not that I know of and it gets harder from here.


METHOD 2


MAKE YOUR OWN ".DESKTOP" FILE

What if you've installed AppImages and need make a desktop shortcut for them or  if there is no "launcher" file on your system for your progam?  or maybe you've written your own Bash Script  or Python program and want a quick desktop shortcut to it.  Well you will have to make your own ".desktop" file.

I'm going to go through this quickly so that you can just get it done.  I encourage you to read more about ".desktop" files and all their options here.

First open a text editor, create a new blank document, and copy & paste the below information into it:


[Desktop Entry]
Version=2.6
Name[en_US]=Darktable
GenericName[en_US]=Graphic Editor
Comment[en_US]=This is an AppImage file link of Darktable
Exec=/home/YOURUSERNAME/AppImages/Darktable2.8.AppImage
Path=/home/YOURUSERNAME/AppImages/
Icon=/home/YOURUSERNAME/Pictures/Icons/darktable.png
Terminal=false
Type=Application
Categories=Application



Now you need to change what you copied & pasted to fit your needs.  Here is what each line means and what you should change:

[Desktop Entry]
All .desktop files start with this

Version=2.6
This is the version of your program and you really don't have to have this line or it doesn't have to be correct but you should try to get it right

Name[en_US]=Darktable
This is the name that will appear under your new desktop shortcut

GenericName[en_US]=Graphic Editor
This is a general type of application i.e. webbrowser, text editor, graphic editor etc.

Comment[en_US]=This is an AppImage file link of Darktable
Whatever you want to help you know about this shortcut

Exec=/home/YOURUSERNAME/AppImages/Darktable2.8.AppImage
This is the path to and your programs startup command.  My program's startup command is "Darktable2.8.AppImage" and that program is located in "/home/YOURUSERNAME/AppImages/" directory.  This program happends to be in my home directory in the folder AppImages.  If your's is similar you would change YOURUSERNAME to your logon or user name.

Path=/home/YOURUSERNAME/AppImages/
This is path to your program and where your program will startup

Icon=/home/YOURUSERNAME/Pictures/Icons/darktable.png
This is the path to and file name of the graphic you want to use as an icon for your program.  I have a folder in my "Pictures" folder called "Icons" where I keep all my icon graphics. Change this to fit your needs.

Terminal=false
Is this a Terminal program or command.  i.e. if this was a bash script you would set this to "true".

Type=Application
This specification defines 3 types of desktop entries: Application, Link or Directory.

Categories=Application
Categories in which the entry should be shown in a menu.

There are more options you can add and for a better explanation you really should follow this link and read more about it.

Okay, once you've changed the ".desktop" file to fit your needs save it to the DESKTOP directory with the extension ".desktop".  Make sure you have you icon graphic saved in the proper place that was referenced in the ".desktop" file you just saved.

The ".desktop" file should have appeared on your desktop after you saved the ".desktop" file to the DESKTOP directory but it will look like a text file and will not function yet.


You will now need to Right Click on the ".desktop" file on your desktop and select properties. Now click on the PERMISSIONS tab and check the "Allow executing file as program" option.  Just closing Properties saves your change (click on the X in the upper right corner).



Okay last step.  Once again Right Click on your ".desktop" file on your desktop and you should have an option that says "Allow Launching"  just Left Click on it and it will then be ready and the icon should change to what your use to seeing associated with your program.



You can now double click on your new desktop shortcut and it should start your program.


***NOTES:  When editing make sure you mind your Capital Letters in file and path names.  I tried the "~" shortcut for my home directory but it did not work for me.  Watch the "/" and make sure you have them in the right places.  When you copy .desktop file from one of the two directories they tend to have a lot more options set in their .desktop files.  You can make .desktop files that reference Bash scripts just make sure to change the Terminal=false to Terminal=true and in the Exec= part this works for me "Exec=/PathToBashScript/bash BashScriptName.sh" .  The same will work for Python too.

***ICON'S Locations.  The images used as the icons are either referenced directly with their entire path listed in the .desktop file (ICON=/path/image) or are stored in a couple of system directories. One is  "/usr/share/pixmaps" and the second is "/usr/share/icons" (most live here).  If you just see a name without a path listed in the .desktop file (i.e. Icon=imagefile) then it will be stored based off the variable $prefix which can be /usr, /usr/local or ~/.local or in one of the two directories listed above.

No comments: