1

I would like to ask some questions about .desktop files, and figure something out that I think would be rather nifty.

I will start by saying I am running [elementary OS Luna] with kernel [3.2.0-65-generic-pae].

I know a little about .desktop files, and what they do. I learned from someone over at the eOS IRC. One little thing always bugged me about making my own. When you open an application via its .desktop, it will light up that icon in ubuntu, I believe. In eOS, we get a little light indicator as well. It stays WITH the icon itself. When you make your own, it does not.

For example, I made a .desktop that attaches to a .sh that would open a .jar. When I click the icon, it does what I would like, and opens. The only thing I dislike is the fact that there is a whole new icon that pops up. It is the Oracle Java icon, and it is blurry, as well as an eye-sore. I was curious if there is a command I can put in my .desktop that will enable it to only light up the original icon, and such as other apps do.

Also, I was curious if there was a way to convert things like .png to the file format of .desktops icons.

Thank you in advanced.

4
  • 1
    You can use .png files as the .desktop icon. Just write in the icon location as /home/user/Pictures/Logos/javaicon.png
    – Tim
    Jul 19, 2014 at 8:41
  • Thank you, Tim. I will have to try that out. Do you have any clue as of the other thing?
    – Brendon
    Jul 19, 2014 at 8:43
  • No I don't sorry...
    – Tim
    Jul 19, 2014 at 8:51
  • 1
    As to the second part, have a look at askubuntu.com/q/36434/158442
    – muru
    Jul 19, 2014 at 9:12

2 Answers 2

3

First I suggest you watch log for your file:

Open Terminal
auditctl -a exit,always -w /path/to/file and press Enter.
sudo nano /var/log/audit/audit.log and press Enter to watch log.


Full Freedesktop.org reference: Desktop Entry Specification

Freedesktop example

[Desktop Entry]
Version=1.0
Type=Application
Name=Foo Viewer
Comment=The best viewer for Foo objects available!
TryExec=fooview
Exec=fooview %F
Icon=fooview
MimeType=image/x-foo;
Actions=Gallery;Create;

[Desktop Action Gallery]
Exec=fooview --gallery
Name=Browse Gallery

[Desktop Action Create]
Exec=fooview --create-new
Name=Create a new Foo!
Icon=fooview-new  

Quote: Icon to be shown togheter with the action. 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. Implementations may choose to ignore it.

READ ABOUT


Good short tutorial by Joe Reimero: Anatomy of a .desktop File

Joe Reimero example

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=$HOME/MyApplication
Name=My Application
Icon=$HOME/Icons/MyIcon.png

By Joe that I agree also the path to the Icon can be absolute OR relative and it depends on what standard you have chosen to construct your symbolic link. Traditionally it is PNG.


Great tutorial especial for you: Turn your Java apps Gnome-Shell friendly

[Desktop Entry]
Version=10.5.1
Name=IntelliJ IDEA Ultimate Edition
Comment=The Most Intelligent Java IDE
Categories=Applications;Development;
Encoding=UTF-8
Exec=env IDEA_CLASSPATH\=../lib/asm.jar /home/diego/bin/ideaIU-10.5/bin/idea.sh
GenericName=IntelliJ
Icon=/home/diego/bin/ideaIU-10.5/bin/idea128.png
MimeType=text/x-java
Terminal=false
Type=Application
URL=http://www.jetbrains.com/idea  

Note for line:

Exec=env IDEA_CLASSPATH\=../lib/asm.jar /home/diego/bin/ideaIU-10.5/bin/idea.sh

where you see CLASSPATH variable next to exec.


Any chance that it also can help how it say OS Luna:

.desktop files follow the freedesktop.org Desktop Entry Specification. They should be installed in /usr/share/applications. Users may create their own launchers by putting .desktop files in ~/.local/share/applications.

READ

11
  • So, if I am reading correctly, mind you it is 5 am where I live, I just have to add the desktop action crew?
    – Brendon
    Jul 19, 2014 at 9:09
  • I'm very sorry. That probably sounded very idiotic. I am not entirely sure what you are doing that will keep the second icon from popping up. Further elaboration would be nice.
    – Brendon
    Jul 19, 2014 at 9:12
  • I think for OS Luna need to say it can be a little bit specific configuration. Obviously you should to find reference at OS Luna help. It's very possible.
    – swift
    Jul 19, 2014 at 9:20
  • found tutorial especial for you, editing answer
    – swift
    Jul 19, 2014 at 9:30
  • Alright, I've a bit down. I am able to get the icon to be as I wish. The only problem is I can not get it to stay as that icon. For example, if I were to set the .desktop icon as cat.png, but I wanted to open Midori web browser, how would I stop the midori web browser icon from show when it opens?
    – Brendon
    Jul 19, 2014 at 9:44
1

A .desktop launcher file can likely just be (sort of) simplified down to something like the following

[Desktop Entry]
Type=Application
Name=Google Maps
Exec=google-chrome --app=https://www.google.co.uk/maps/@52.0547887,-1.3424413,11z
Comment=Open Google Maps
GenericName=Open Google Maps
Icon=/home/wilf/.local/Google-Maps-icon.png
Categories=GTK;Utility;
Keywords=Maps;
Hidden=false
NoDisplay=false
Terminal=false

Where:

  • You need both [Desktop Entry] and Type=Application to say it is a application launcher.
  • Name is its name
  • Exec is the command it runs
  • Comment/GenericName desribe it (not always needed)
  • Icon is the path to a icon or a icon from the theme(s) you are using in /usr/share/icons (not always needed, but the default icon if often annoying)
  • Categories - specifies the category it is in (useful for menus - not always needed)
  • Keywords are words that can be used to find it when you search for it (not always needed).
  • Hidden/NoDisplay set to false make sure it is displayed (not always needed).
  • Terminal whether to run in terminal or not`.

For changing the icon, you just need to change the Icon line to specify a different icon - e.g. to use a text editor icon from /usr/share/icons:

Icon=accessories-text-editor

or you can specify a path to a icon file

Icon=/home/wilf/.local/Google-Maps-icon.png

This is also possible by right-clicking on the launcher in most file mangers and selecting properties: enter image description here

Then clicking on the icon and selecting a new one - note if it is in /usr/share/applications you probably need permissions to edit the file.

N.B.

I can't exactly remember why (probably made it for something), but I appear to have the following script that can create .desktop launchers - here it is:

#!/bin/bash
if [ "$1" = "--help" ]; then
   echo -e "\e[1mUsage:\e[0m\n  create-launcher [OPTIONS...] [FILENAME] - create a launcher\n\e[1mHelp Options:\e[0m\n  --help    Show help options\n\e[1mApplication Options:\e[0m\n  -n NAME       Sets the name of the New launcher\n  -c COMMAND    Sets the command the launcher will be used to Launch\n  -t COMMENT    Sets the comment used to describe the launcher\n  -i ICON       Specifies an icon filename or stock icon to display.\n\n\e[1mNote\e[0m - ideally all of the above options should be used, mainly the Name option as it used to create the name of the launcher, and the command option as that is required for the launcher to work."
   exit
fi
while getopts n:c:t:i: option
do
    case "${option}"
    in
        n) NAME=${OPTARG};;
        c) COMMAND=${OPTARG};;
        t) COMMENT=${OPTARG};;
        i) ICON=${OPTARG};;
    esac
done
FILE=$HOME/.local/share/applications/$(echo $NAME | sed 's/ /-/g').desktop
NOFILE=$HOME/.local/share/applications/.desktop
if [ $FILE = $NOFILE ]; then
   echo -e "ERROR: Please enter atleast the Name for the launcher - for more info run\n    create-launcher --help" 
   exit 1
else
echo "New launcher created at $FILE"
echo -e "[Desktop Entry]\nType=Application" > $FILE
echo Name=$NAME >> $FILE
echo Exec=$COMMAND >> $FILE
echo Comment=$COMMENT >> $FILE
echo Icon=$ICON >> $FILE
echo -e "Hidden=false\nNoDisplay=false\nTerminal=false\n#X-GNOME-Autostart-enabled=true" >> $FILE
chmod +x $FILE
fi
exit

This can be saved to a executable file, and creates a simple launcher like the following (except the fields are filled by specifying the scripts options - see ./create-launcher --help) in ~/.local/share/applications (which should mean the launcher shows in menus etc)

[Desktop Entry]
Type=Application
Name=
Exec=
Comment=
Icon=
Hidden=false
NoDisplay=false
Terminal=false
#X-GNOME-Autostart-enabled=true

The last line is not important unless it is used elsewhere to start a program on login.

1
  • This is very interesting. You gave me a lot of information, and I will look into it. Thank you.
    – Brendon
    Jul 19, 2014 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .