GearHack

: :

Add Comment | Related Links | TrackBack
Related Content

Relative Path with Linux .desktop Files

The Linux .desktop files--files with ".desktop" extension--allows Linux window managers to launch scripts and executables with visible icons. It's pretty much the Windows shortcuts in the Linux world. Unlike the Windows shortcuts, Linux .desktop files are text files that you can edit easily. It includes entries for execution path and executable to run. A few generations back, you are able to specify relative path using environment variables (e.g. ${HOME}/bin/scripts/UNIX). But you can no longer use environment variables in today's Linux distributions.

However, there is a way to still use relative path in the Linux .desktop file. And that is to leave out the forward slash on the path. For example, the following entries will no longer work in the .desktop file, because the ${HOME} variable is no longer accepted:

  Exec="${HOME}/bin/scripts/UNIX/Prototype.bash"
Path=${HOME}/bin/scripts/UNIX

If you try to launch that icon, you'll get the following error message:

"There was an error launching the application.

Details: Failed to change to directory '${HOME}/bin/scripts/UNIX' (No such file or directory)."

But the following simple change to the .desktop file makes all the difference:

  Exec="Prototype.bash"
Path=bin/scripts/UNIX

As you can see, today's Linux distribution defaults icon launch to your home directory. And it still accepts a relative path from your home directory if you don't provide the forward slash. So the relative path capability hasn't been completely taken away. You can still take advantage of it knowing this trick.

Mel
Wed, 13 Mar 2013 03:52:14 +0300

http://standards.freedesktop.org/desktop-entry-spec/

Exec=bash -c '_PWD="$PWD"; cd "`echo $0 | sed s/filename.desktop$//`"; ./program.sh run; cd "_PWD"' %k

Alexandre Magno
Mon, 07 Apr 2014 06:19:38 +0400

This is great info, thanks for sharing!

nexayq
Fri, 29 Jul 2016 14:29:47 +0400

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

TrackBack

Send Ping | TrackBack URL | Spam Control

Title: Ubuntu 13.04 Desktop File Restrictions
Weblog: GearHack
Excerpt: A few month ago, I showed you how to use "Relative Path with Linux .desktop Files". Back then, I complained about the desktop having more and more limitations. Only a few month later, when I installed Ubuntu 13.04 that I realized they even took away the luxury of being about to use relative paths. E . . .
Tracked: Thu, 27 Jun 2013 09:28:43 +0400

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 8 - 5?
Click button only once, please!

Messages, files, and images copyright by respective owners.


Articles | Wiki
Forums | Latest | RSS
Library | Links | News
Search | Store | Help

51 Users Online


Hacking Digital Cameras
Fun for Photographers

Amazon Associate

Copyright © 2004 - 2017. All Rights Reserved.