Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Desktop Launcher for Python Script Starts Program in Wrong Path

I can not launch a python script from a .desktop launcher created on Linux Mint 17.1 Cinnamon.

The problem is that the script will be launched in the wrong path - namely the home folder instead of the directory it is placed in. Thereby it can not find other vital files accompanying it in its folder and hence does not work.

To examine that misbehaviour I created a short script to check the folder a python script is executing in:

#!/usr/bin/env python

import subprocess
import time

subprocess.call(["pwd"], shell=True)
time.sleep(7)  # to get a chance to read the output

Executing it from its own folder gives the output:

/home/myusername/PythonProjects

I am setting a desktop launcher via Nemo's menu. Now executing the same script yields:

/home/myusername

I do not understand this behaviour. How could I create a working desktop launcher for my python script?

like image 490
pykong Avatar asked May 29 '15 19:05

pykong


1 Answers

The page describes the format of .desktop files.

You may note the "Path" element, which specifies the working directory for the file to be run in. In your case you would want a desktop file that specified

Path=/home/myusername/PythonProjects

If Nemo doesn't allow you to set the Path element you may need to edit the desktop file by hand. The .desktop files are text files and you can probably find them in /home/myusername/.local/share/applications/

like image 72
James K Avatar answered Oct 13 '22 20:10

James K