LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Using relative paths in GNOME launcher - workarounds? (https://www.linuxquestions.org/questions/linux-desktop-74/using-relative-paths-in-gnome-launcher-workarounds-4175430136/)

rocketb 10-02-2012 02:31 PM

Using relative paths in GNOME launcher - workarounds?
 
It would be extremely convenient if I could launch some scripts from a CD. I usually launch these scripts using GNOME desktop launchers. I would like the launcher to be able to look at its own working directory, and launch a script in a directory beneath it. The problem is, the launcher file syntax doesn't understand relative paths. Which would force me to use absolute paths, which means the CD always has to have the same mount point. If I could use relative paths, it wouldn't matter, and everything could be copied to the hard drive and everything would still work.

Launcher can't understand this because it doesn't understand shell variables, but this is basically what I want:
Exec=$PWD/scripts/myscript
or
Exec=./scripts/myscript

I tried using a command like this in the launcher:
Exec=bash -c "$PWD/scripts/myscript"

However, when bash is called, it is a new instance of bash, and so the working directory becomes default (/home/username), not the directory that contains the launcher.

I've nearly resigned myself to having to having to use absolute paths, but if anyone can figure out a way to trick launchers into doing what I want, it would be appreciated.

- rocketb

David the H. 10-04-2012 02:38 PM

"Launchers" generally use the standardized desktop file syntax. In this syntax the exec line accepts %f style entries to stand for file/directory names passed to them.

See here for the format details.
http://standards.freedesktop.org/des...exec-variables

I don't know if you can get it to do what you want, though. I don't even know if there is a "working directory" involved. But I suggest taking a read of the above.

John VV 10-04-2012 07:20 PM

Quote:

It would be extremely convenient if I could launch some scripts from a CD.
that is a very BAD idea

so bad that even Microsoft has ( by default) DISABLED auto run .

you DO not want a computer that can do that automatically


but if you must

do not try a *.desktop file

use a shell script

but by default it will NOT be executable ( you really do NOT want a script on a cd to just run )
so you will have to call it in the terminal
Code:

sh ProgramName.sh

David the H. 10-07-2012 11:30 AM

To be fair, I didn't see anything saying he wanted autorun, just that he wanted to be able to manually launch a script that exists on a cd from a desktop icon or something.

Actually, I'm not completely sure I understand the entire problem. I think it has to do with the disc device being variable, so he can't have his desktop file point to it directly.

A better solution would perhaps then be to configure udev to create a specific device symlink for his drive and/or certain cds. Then he would always be ensured of a permanent path.

http://www.reactivated.net/writing_udev_rules.html

rocketb 10-17-2012 09:40 AM

Quote:

Originally Posted by David the H. (Post 4799492)
To be fair, I didn't see anything saying he wanted autorun, just that he wanted to be able to manually launch a script that exists on a cd from a desktop icon or something.

Actually, I'm not completely sure I understand the entire problem. I think it has to do with the disc device being variable, so he can't have his desktop file point to it directly.

A better solution would perhaps then be to configure udev to create a specific device symlink for his drive and/or certain cds. Then he would always be ensured of a permanent path.

Correct, I don't want autorun, I just want to be able to launch the script on the cd from a desktop launcher.

I briefly looked at that udev rules page, but that seems to be able device naming, which isn't really the problem. The device is always /dev/cdrom. The mount point is the variable, as GNOME creates a mount point using the label of the cd (e.g. /media/mydiscname). I can use that path in the script, however, I will have to make sure that the CDs are always made with the same volume label. Also, it would break if copied to the hard drive.

Essentially, I'm trying to make it really easy for the end user. I want them to pop in the CD, double-click on the script they need, and they're done. Also, trying to avoid any pitfalls in the future if someone other than myself has to modify the CD.

rocketb 10-17-2012 09:45 AM

Quote:

Originally Posted by David the H. (Post 4797427)
"Launchers" generally use the standardized desktop file syntax. In this syntax the exec line accepts %f style entries to stand for file/directory names passed to them.

See here for the format details.
http://standards.freedesktop.org/des...exec-variables

The %k variable almost does what I want. However it also includes the name of the desktop launcher as well. For example, it would translate to "/media/discname/launcher.desktop". I need to call a script from "/media/discname/scripts/scriptname.bash". If I could strip out that launcher name, it'd be perfect.


All times are GMT -5. The time now is 06:44 PM.