Syntax for .desktop files

Please post suggestions for improvement of Cinnamon here
https://github.com/linuxmint/Cinnamon
Post Reply
Person from Porlock
Level 1
Level 1
Posts: 7
Joined: Mon Oct 02, 2017 2:21 pm

Syntax for .desktop files

Post by Person from Porlock » Fri May 11, 2018 4:54 pm

Hi all. I have written some software which runs fine when executed from the terminal. It needs to access some resources which live in an imaginatively titled "resources" folder in the same folder where the executable lives. I wanted to have a desktop launcher for this so created a .desktop file which looks like this:

[Desktop Entry]
Type=Application
Terminal=true
Name=the_executable
Exec=/home/me/path/to/the_executable

At present it still partly needs a terminal to be running (for couts and a few cins) hence the "true" above.

However when launched this way the executable fails to find its resources. I assume that's because somehow we are still not in the home directory of the executable. Is there a syntax to set this in the .desktop file? If not do I perhaps need to add something to my PATH variable (which seems an inelegant way of doing things).

I'm using Mint 18.2 (64-bit version).

Thanks in advance!

MrEen
Level 5
Level 5
Posts: 694
Joined: Mon Jun 12, 2017 8:39 pm

Re: Syntax for .desktop files

Post by MrEen » Fri May 11, 2018 5:44 pm

I've not had that need, but I think if you used this it might work:
[Desktop Entry]
Type=Application
Terminal=true
Name=the_executable
Path=/home/me/path/to
Exec=the_executable

Person from Porlock
Level 1
Level 1
Posts: 7
Joined: Mon Oct 02, 2017 2:21 pm

Re: Syntax for .desktop files

Post by Person from Porlock » Fri May 11, 2018 5:57 pm

Thanks for your reply. No: unfortunately if I do that there simply pops up a dialogue box saying "there was an error launching the application". Is "path" a valid key in the .desktop syntax? If so I am doing something wrong. Without this, the application executes fine to begin with, but complains that it can't find certain files located in the resources folder of its home directory.

MrEen
Level 5
Level 5
Posts: 694
Joined: Mon Jun 12, 2017 8:39 pm

Re: Syntax for .desktop files

Post by MrEen » Fri May 11, 2018 6:00 pm

Yes to the Path question. I got it from here: https://wiki.archlinux.org/index.php/Desktop_entries

Sorry that I can help any further.

Person from Porlock
Level 1
Level 1
Posts: 7
Joined: Mon Oct 02, 2017 2:21 pm

Re: Syntax for .desktop files

Post by Person from Porlock » Fri May 11, 2018 6:28 pm

Indeed it is. Thank you for your time looking into this.

The issue persists. The .desktop file currently stands at
[Desktop Entry]
Type=Application
Encoding=UTF-8
Version=1.0
Terminal=true
Name=the_executable
Exec=/home/me/path/to/the_executable

I would like to understand why the program runs perfectly from terminal, but cannot find files in its home directory when executed from this desktop launcher.

(for clarification: It's a fairly basic c++ program which merely tries to open various files whose path it is given as a c string.)

rene
Level 7
Level 7
Posts: 1764
Joined: Sun Mar 27, 2016 6:58 pm

Re: Syntax for .desktop files

Post by rene » Fri May 11, 2018 7:04 pm

Horse's mouth with respect to .desktop files is https://standards.freedesktop.org/deskt ... index.html.

Indeed it mentions the Path key so wouldn't know why that's not working for you: https://standards.freedesktop.org/deskt ... 01s06.html

Person from Porlock
Level 1
Level 1
Posts: 7
Joined: Mon Oct 02, 2017 2:21 pm

Re: Syntax for .desktop files

Post by Person from Porlock » Thu Jun 21, 2018 5:34 pm

Hi everyone - in case anyone else had an analogous problem I will post the solution I found. The software I wrote needed to access external data which in my case consisted of some .json files. If you want to do this you need to specify in the desktop entry file the MIME type(s) your application will be working with. An incomplete list may be found at https://developer.mozilla.org/en-US/doc ... MIME_types for example. So in my case the desktop file required the line

Code: Select all

MimeType=application/json
where the value(s) on the right hand side will be application-dependent.

The moral of the story for me is that a program in and of itself may be happy working with other resources, but for some kinds of resources the .desktop file will
also need to be told what those are.

Thank for the other comments, if I had mentioned this aspect of using json files I am sure you would have told me straight away (but, if I had realised it myself I would not have posted). Please all do post corrections if the 'solution' I have posted is misinformed in any way.

Post Reply

Return to “Cinnamon”