1

Ubuntu 12.04 32-bit

I am trying to manually create a .desktop file to launch an application. I wish to execute the command:

java -jar ~/.osbuddy/osbuddy.jar

When I run my .desktop file. However, this does not work. I then tried:

java -jar /home/${USER}/.osbuddy/osbuddy.jar

which did not work either.

Finally,

java -jar /home/branon/.osbuddy/osbuddy.jar

worked fine. I manually executed all of the above lines through the terminal and it launched the program fine. Why won't it work in a .desktop file?

Thanks for any light you can shed. This is my first time on AskUbuntu so I apologise if I'm ignoring some customary rules of this form. If I've transgressed, please correct me.

2

2 Answers 2

4

The command in a .desktop file is not run by a shell but using some system call. Because of that you can't use shell syntax like ~ or ${USER} there

3
  • So, to clarify: there's no way to get around using the full path in the Exec line? Thanks! Apr 8, 2015 at 19:46
  • 1
    You could explicitly use a shell, like sh -c 'java -jar ~/.osbuddy/osbuddy.jar'. But I think using the full path is usually the better solution. Apr 8, 2015 at 19:52
  • Thank you. That is what I was looking for. Marked as solved :) Apr 8, 2015 at 20:26
1

As Florian Diesch says, tilde expansion and parameter expansion is not supported in launchers (i.e., .desktop files). But if you need to use them--or other shell expansions--you can do so by making the launcher execute a shell with command-line arguments telling the shell to run a specific command and exit.

Thus you can make your command:

sh -c 'java -jar ~/.osbuddy/osbuddy.jar'

I've used sh (which in Ubuntu is dash) rather than bash) for efficiency and minimalism. But if you needed an advanced feature provided by bash, you could use that instead.

If the path ~/.osbuddy/osbuddy.jar is valid for multiple users and multiple users will be using the launcher, I recommend the sh -c (or if you prefer, bash -c) way. However, if this is only for you and your main goal is to avoid typing /home/brannon...well, passing the command to sh -c involves some extra typing, too.

1
  • Thank you for the in-depth explanation -- I was woefully unaware of what sh and bash actually were :) Apr 8, 2015 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .