5

I created a simple desktop file to check the connectivity of remote location in which Exec=ping 192.168.0.9. But one file created with #!/usr/bin/env xdg-open before Desktop Entry and another without #!/usr/bin/env xdg-open and both worked the same. Then What is the use of it in desktop file? What does it mean?

d a i s y
  • 5,511

1 Answers1

4

As per this answer , the use of #!/usr/bin/env xdg-open was meant to serve as a way to launch applications that referenced in .desktop file via command line. But as of now, it doesn't work and only opens .desktop file as text file in gedit. Nowadays , if you want to launch a .desktop app via command line, you must do some pre-processing of the file itself.

As for use of #! it basically tells your computer which interpreter to use with this file. In this case, /usr/bin/env which will return path to xdg-open command (i.e, this calls xdg-open to read and execute your file ) .

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Ok. Got it but you said "to launch a .desktop app via command line, you must do some pre-processing of the file itself. and what is that pre-process? Could you tell me? – d a i s y Aug 08 '16 at 11:31
  • Preprocessing is just extracting the Exec= line. And there's plenty of tools for that: grep, awk,sed,python,perl. Just whatever works for you. – Sergiy Kolodyazhnyy Aug 08 '16 at 16:44