Friday, February 8, 2019

How to create Custom Launch Icon for a program/executable in Ubuntu-16.04

This intention of this post is to create Custom Launch Icon for any program or executable that you have in Ubuntu.

For this experiment I have used Ubuntu-16.04 but you can have any distribution of Ubuntu of your choice.

To start with let me have the following

1. A tiny c program
2. An Icon to click

The C Program
#include <stdio.h>
int main(void){
        printf("Hello World... Welcome to Ravaneswaran Chinnasamy's Blog.\n");
        printf("Checkout :  https://ravaneswaran-chinnasamy.blogspot.com\n");
        printf("\n");
        printf("Press any key to exit the program...\n");
        getchar();
        return 0;
}

I have copy pasted the above program statements in a file named "helloworld.c" and executed the following command to make an executable out of it...
> gcc -o helloworld helloworld.c
now you find the executable version of helloworld.c in the folder where you executed the above command, move the executable to a preferred location, in my case /opt/bin (this location does not exist by default, you have to create one if you want one)

Similarly I have downloaded a .ico file from Internet and moved to a comfortable location(/opt/icons) to access.

Now we have to create a .desktop file and should fill it with the following properties, let the file name be hello-world.desktop 
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=true
Name=Hello World
Icon=/opt/icons/hello-world.ico
Path=/opt/bin
Exec=/opt/bin/helloworld
StartupNotify=false
StartupWMClass=HelloWorld
OnlyShowIn=Unity;
X-UnityGenerated=true
the details about each of the key is given below...

Courtesy : standards.freedesktop.org

Key Description Type Mandatory
Type This specification defines 3 types of desktop entries: Application (type 1), Link (type 2) and Directory (type 3). To allow the addition of new types in the future, implementations should ignore desktop entries with an unknown type. string YES
Version Version of the Desktop Entry Specification that the desktop entry conforms with. Entries that confirm with this version of the specification should use 1.1. Note that the version field is not required to be present. string NO
Name Specific name of the application, for example "Mozilla". localestring YES
GenericName Generic name of the application, for example "Web Browser". localestring NO
NoDisplay NoDisplay means "this application exists, but don't display it in the menus". This can be useful to e.g. associate this application with MIME types, so that it gets launched from a file manager (or other apps), without having a menu entry for it (there are tons of good reasons for this, including e.g. the netscape -remote, or kfmclient openURL kind of stuff). boolean NO
Comment Tooltip for the entry, for example "View sites on the Internet". The value should not be redundant with the values of Name and GenericName. localestring NO
Icon Icon to display in file manager, menus, etc. If the name is an absolute path, the given file will be used. If the name is not an absolute path, the algorithm described in the Icon Theme Specification will be used to locate the icon. localestring NO
Hidden Hidden should have been called Deleted. It means the user deleted (at his level) something that was present (at an upper level, e.g. in the system dirs). It's strictly equivalent to the .desktop file not existing at all, as far as that user is concerned. This can also be used to "uninstall" existing files (e.g. due to a renaming) - by letting make install install a file with Hidden=true in it. boolean NO
OnlyShowIn, NotShowIn A list of strings identifying the desktop environments that should display/not display a given desktop entry.
By default, a desktop file should be shown, unless an OnlyShowIn key is present, in which case, the default is for the file not to be shown.
If $XDG_CURRENT_DESKTOP is set then it contains a colon-separated list of strings. In order, each string is considered. If a matching entry is found in OnlyShowIn then the desktop file is shown. If an entry is found in NotShowIn then the desktop file is not shown. If none of the strings match then the default action is taken (as above).
$XDG_CURRENT_DESKTOP should have been set by the login manager, according to the value of the DesktopNames found in the session file. The entry in the session file has multiple values separated in the usual way: with a semicolon.
The same desktop name may not appear in both OnlyShowIn and NotShowIn of a group.
string(s) NO
DBusActivatable A boolean value specifying if D-Bus activation is supported for this application. If this key is missing, the default value is false. If the value is true then implementations should ignore the Exec key and send a D-Bus message to launch the application. See D-Bus Activation for more information on how this works. Applications should still include Exec= lines in their desktop files for compatibility with implementations that do not understand the DBusActivatable key. boolean NO
TryExec Path to an executable file on disk used to determine if the program is actually installed. If the path is not an absolute path, the file is looked up in the $PATH environment variable. If the file is not present or if it is not executable, the entry may be ignored (not be used in menus, for example). string NO
Exec Program to execute, possibly with arguments. See the Exec key for details on how this key works. The Exec key is required if DBusActivatable is not set to true. Even if DBusActivatable is true, Exec should be specified for compatibility with implementations that do not understand DBusActivatable. string NO
Path If entry is of type Application, the working directory to run the program in. string NO
Terminal Whether the program runs in a terminal window. boolean NO
Actions Identifiers for application actions. This can be used to tell the application to make a specific action, different from the default behavior. The Application actions section describes how actions work. string(s) NO
MimeType The MIME type(s) supported by this application. string(s) NO
Categories Categories in which the entry should be shown in a menu (for possible values see the Desktop Menu Specification). string(s) NO
Implements A list of interfaces that this application implements. By default, a desktop file implements no interfaces. See Interfaces for more information on how this works. string(s) NO
Keywords A list of strings which may be used in addition to other metadata to describe this entry. This can be useful e.g. to facilitate searching through entries. The values are not meant for display, and should not be redundant with the values of Name or GenericName. localestring(s) NO
StartupNotify If true, it is KNOWN that the application will send a "remove" message when started with the DESKTOP_STARTUP_ID environment variable set. If false, it is KNOWN that the application does not work with startup notification at all (does not shown any window, breaks even when using StartupWMClass, etc.). If absent, a reasonable handling is up to implementations (assuming false, using StartupWMClass, etc.). (See the Startup Notification Protocol Specification for more details). boolean NO
StartupWMClass If specified, it is known that the application will map at least one window with the given string as its WM class or WM name hint (see the Startup Notification Protocol Specification for more details). string NO
URL If entry is Link type, the URL to access. string YES

With that I have given the details of every property we have, now we have to make a important move to make our program appear when we search "Hello World" from "Search your computer" Icon on the Launch bar, to achieve that we have to copy the hello-world.desktop file to two locations...

 /usr/share/applications
~/.local/share/applications

To do that use the following command...
> sudo cp <path-to-the-hello-world-script/hello-world> /usr/share/applications
The above command may prompt you for password, provide the password to move the file successfully...
This move is for the entire system level.

The second move is achieved as given below...
> cp <path-to-the-hello-world-script/hello-world> ~/.local/share/applications
This move is for the User level.

Now if you try to search the application by clicking on the "Search your computer" Icon on the launch bar, our program would appear and click the icon to run it.
.
.
.
Thanks

No comments:

Post a Comment

Addressing Modes of 8080 / 8085 MicroProcessor

Hi,   In this post I am going to talk about different addressing modes of 8080/8085...without much talking let us get into the topic.   Ther...