Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to set the 'Path' variable in a .desktop file relative to the location where the desktop file is located and I can't manage to do that.

When I don't declare it or set it to blank it defaults to my home folder no matter where I run it from; and it doesn't accept values relative to my current location within the file system.

share|improve this question
    
I've had this problem. I've found workarounds, although sometimes radically complicated depending upon what you are doing. Are you using a work around at this time? If not, I may be able to help with that. I have not found xdg docs that explain much on this. –  bambuntu Apr 6 '12 at 20:42
    
OP are you still looking for an answer? If so, you may need to repost your question as this is marked for closure. Regards, –  Ringtail Apr 7 '12 at 23:15

2 Answers 2

up vote 1 down vote accepted

You cannot set the CWD inside a .desktop file. If you want an application to have a specific CWD, you will need to write a simple wrapper script for the application, that looks something like this:

#!/bin/sh

(cd /where/you/want/it/to/be && exec your_program)

You can replace your_program there with $@ and run the script with your_program as an argument, like run-in-dir.sh your_program. This way you can use the same script to wrap any program you want to start in that directory.

share|improve this answer

You can kludge around this by using an in-line bash mini-script on your Exec. This will add the .desktop file's path to PATH prior to running your command.

Exec=bash -c "export PATH=$PATH:`dirname %k`; your_command"

%k will be substituted by the path of the desktop file itself. The dirname command chops off the filename part, leaving only the directory. Once PATH is set like this, your_command can be invoked without a full path.

share|improve this answer
    
I clicked to quick and voted up the wrong one but your solution is perfect. –  CrandellWS Mar 28 at 19:58
    
this could work great with this other question/answer stackoverflow.com/a/3464561/1815624 –  CrandellWS Mar 28 at 20:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.