pythonlinuxfreedesktop.org

Linux desktop file Exec doesn't used the user session


I have a python script file that works perfectly when I use it from the terminal.

Now I have created the following .desktop file in order to launch it easily:

[Desktop Entry]
Name=Test
GenericName=Test
Comment=My test script
Type=Application
Exec=/opt/test.py
Icon=/opt/test.png
Categories=Utils;

When I launch it the GTK window appear but clicking a button that call an init.d script make it working not properly.

Therefore adding Terminal=true make it working perfectly but I don't want to have that terminal open.

So I have then put the following code in order to log the environment variables:

import os

with open("/tmp/py_env.log", "w") as env_log:
  env_log.write(str(os.environ))

and found differences.

So my question is how to write the .desktop file so that my application is running like if I start it from my terminal (without having an opened terminal :))


Solution

  • Thanks anyone to have participate to this question.

    I have solved this issue by implemented use of pkexec instead of gksudo. pkexec seems to reuse the current user environment then I don't have this issue anymore.

    Thanks.