Desktop Files

Contents

What are .desktop files

Desktop files installed by the system generally live in /usr/share/applications, but it is advised that users who create their own desktop files install them to ~/.local/share/applications.

In the path: ~/.local/share/applications the beginning part ~/ refers to the users directory while .local means local is a hidden folder. To view hidden files and folders in PcManFm, press Ctrl-H.

There main purpose is to execute a program from the main menu. They look like this.

[Desktop Entry]
Version=1.0
Name=UNetbootin
Comment=Tool for creating Live USB drives
Categories=Application;System;
Exec=/usr/bin/unetbootin
Terminal=false
Type=Application
Name[en_US]=UNetbootin
GenericName[en_US]=UNetbootin
Comment[en_US]=Tool for creating Live USB drives
Icon=unetbootin


This is one for UNetBootin. Most of the entries are self explanatory. There are a number of useful things you can do with desktop files. The scope of this article covers editing .desktop files so as to affect where an application appears in the main menu and using .desktop files to initiate scripts at startup.

Bodhi like most linux distributions follows the freedesktop.org standard for .desktop files. A complete description of the desktop file format can be found here: Desktop Entry Specification.


Main Menu Entries

In the desktop file there is a 'Categories' section. It is there that you can change where an application appears in the main menu. In the example I used above, you see

Categories=Application;System;

This means that Unetbootin will appear in Application → System, in the main menu. Therefore, should you want to change where Unetbootin (or any other application) appears in the main menu, all you need to do is edit the Categories entry. So for example, if I wanted Unetbootin to be in Applications → Accessories. I would edit the unetbooting desktop file so that the Categories line looks like this.

Categories=Application;Accessories;

Note the use of semicolons.

desktop files and bash Scripts

The Exec entry in the desktop file is very useful indeed. It denotes what to execute. In the unetbootin example about, it is saying, execute unetbooting found in this path - /usr/bin/unetbootin. So what? well you can use this for all kinds of useful things.

Say you have a bash file you want to execute at startup. you can add the path to the bash file. By creating a .desktop file, you make it so that it can be added to startup applications. Admittedly there are other way to achieve this, but I think this is a pretty cool use of these files, and it makes life easier.

So, for example. We have a bash script that checks for updates and installs them at startup, that looks something like this.

#!/bin/bash

gksudo apt-get update && gksudo apt-get dist-upgrade

Note that this script uses gksudo, so will prompt for a password, which is not that desireable at startup. There are ways around this, but that is beyond the scope of this article. See sudoers.

We called this script update.sh, and saved it in ~/bash-scripts. In order to have this script executed at startup, we first create a desktop file that calls it, and then add it to startup applications.

The desktop file we create might look like this.

[Desktop Entry]
Version=1.0
Name=update.sh
Comment=update script
Categories=
Exec=~/bash-scripts/update
Terminal=false
Type=Application
Name[en_US]=update.sh
GenericName[en_US]=update.sh
Comment[en_US]=update script
Icon=

Then all we need to do is add it to startup applications by going to main menu → Settings → Setting Panel → Apps → Startup Applications. Click on the Applications tab and scroll to update.sh. Highlight it and click add. Job done.


User Feedback

desktop_files=ip
Did you find this article helpful?
Yes, right on the money!
 
80%(4)
Somewhat. Needs work.
0%(0)
Not really
0%(0)
Not at all.
 
20%(1)

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

 
desktop_files.txt · Last modified: 2012/02/02 12:59 by rbtylee · [Old revisions]


© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks