Syntax for .desktop files

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Person from Porlock

Syntax for .desktop files

Post by Person from Porlock »

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!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Syntax for .desktop files

Post by MrEen »

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

Re: Syntax for .desktop files

Post by Person from Porlock »

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.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Syntax for .desktop files

Post by MrEen »

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

Re: Syntax for .desktop files

Post by Person from Porlock »

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 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Syntax for .desktop files

Post by rene »

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

Re: Syntax for .desktop files

Post by Person from Porlock »

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.
Locked

Return to “Cinnamon”