6

Some people add the following line to a .desktop file:

#!/usr/bin/env xdg-open

But when I checked files under the /usr/share/applications/ in my debian sid, there's no such file that would include this line.

So the question is simple: should it be added or not?

  • 1
    This has to do with .desktop file security and how freedesktop.org people thought it should be implemented. For e.g. on all freedesktop compliant DE's that line is automatically added when you "mark" a .desktop file in ~/.local/share/applications "as trusted" (e.g here's how gnome implemented this ..). So this is not a matter of "If you don't need it to be executable then you don't need it." – don_crissti Jul 10 '16 at 15:48
  • 1
    That should have been an answer, not a comment on the question. – JdeBP Jun 25 '17 at 15:55
7

By having a #! line then the .desktop file can be made executable and run directly (e.g. from a command line, or some file browsers).

The idea behind wrapping with env is to handle different OS's where xdg-open might be in different directories. For example, on Debian the program is in /usr/bin/xdg-open but on another OS it might be elsewhere. The location of env is pretty much fixed and this construct will effectively result in $PATH being searched for the xdg-open program.

On my Debian install no file in /usr/share/applications is marked executable and none of them have a #! line.

So if you want your .desktop file to be executable then you need a #! and wrapping it with env will help in portability. If you don't need it to be executable then you don't need it.

  • Ok, now I get it. – Mikhail Morfikov Jul 10 '16 at 14:39
  • 1
    Many KDE applications have executable .desktop files on debian to. You can find them (if installed) with $ find /usr/share/applications/ -executable -type f – Jonas Stein Jun 27 '17 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.