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.

In a .desktop file you can specify the Path key in a [Desktop Entry] so that the working directory will be that path when the Exec is launched. However, this key does not seem to work when launching items from Quicklist even though the Path key is set in the [Desktop Action] group. Am I doing something wrong or does Unity not support this yet?

If there's no way to do this, can I change the Exec key in some way to get the same effect?

EDIT: For testing purposes, here's an example little script (displaycwd.py) that when run displays the current working path in a Gtk window. There's an example .desktop file that follows showing that when run normally through the Launcher it opens with the right path (/home/ian/Documents in my case). However, activating it through a quicklist, displays the user directory (/home/ian in my case) instead. Just make sure to put the script somewhere in your $PATH.

#!/usr/bin/python
from gi.repository import Gtk
import os

pwd=os.path.realpath(os.curdir)

win=Gtk.Window()
label=Gtk.Label(pwd)
win.add(label)
win.show_all()
win.connect('destroy', Gtk.main_quit)
Gtk.main()

And the .desktop file:

[Desktop Entry]
Name=Display Working Directory
Exec=displaycwd.py
Type=Application
Actions=quicklist
Path=/home/ian/Documents
Icon=folder

[Desktop Action quicklist]
Name=QL Display WD
Exec=displaycwd.py
Path=/home/ian/Documents
share|improve this question
    
The problem isn't executing the program, it's setting the working directory so that the program will find the correct libraries and icons it will need once running. I need this to be a general property so it will work with other people's programs that I don't have control over. If there was a prefix to add on the Exec line to mimic this behavior, that might work. –  Ian B. Feb 2 '13 at 3:12
1  
Submited a bug report to Unity about this: bugs.launchpad.net/unity/+bug/1113883 –  Ian B. Feb 3 '13 at 0:20
    
FYI this will fix your issue: code.launchpad.net/~3v1n0/libindicator/shortcut-path-key/+merge/… –  Treviño Aug 8 '13 at 12:54

1 Answer 1

up vote 1 down vote accepted

Ok, I found a way around that, since it seems that the quicklist ignores the path and other variables, we can create a script that changes the directory, then executes your program.

  1. Create a file called cd.sh or title of your choice, In that file use the following text:

    #!/bin/bash
    cd /home/ian/Documents
    displaycwd.py
    
  2. Mark the file as executable, Right-Click > Properties > Permissions > Allow this file to run as Program.

    Or in terminal:

    chmod +x cd.sh 
    
  3. Place cd.sh in the same location you have displaycwd.py and change the Quicklist to:

    [Desktop Action quicklist]
    Name=QL Display WD
    Exec=cd.sh
    

    This makes the quicklist first call a shell-script that changes the directory, then runs your program.


Solution #2

After looking around I think you can change the Exec line to this:

Exec=bash -c "cd /home/ian/Documents && displaycwd.py"

To pass a string through bash, that changes the directory then runs your program.

share|improve this answer
    
This won't work for me... I can't predict what application a user will need to run and generate custom scripts for them on the fly to put in a launcher. For personal use though, this would be just fine. –  Ian B. Feb 3 '13 at 0:17
    
I think I found another workaround that would only use the launcher file, edited in to end of answer. –  Mateo Feb 3 '13 at 1:16
    
Props to you for the best available answer. Hope Unity will support in future. –  Ian B. Feb 27 '13 at 1:55

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.