How to use $USER in *.desktop file?

I have a working *.desktop file with this line:

Exec=conky -c "/home/john1/.conky/Green Apple Desktop/Gotham1"

I would like to use a general usable line with variable $USER, but that seems to be not possible?

Exec=conky -c "/home/$USER/.conky/Green Apple Desktop/Gotham1"

Google tells me something with env but how to change this line, so its expanding $USER?

Tipps are welcome!

What did it tell you and what did you try after researching and reading?

See here

but how to use that in my Exec?

Have to sleep now …

Why do you think that will help? Did you try it? Did it work?

I’m not playing 20 questions with you.

Sleep well. :wave:

This other link is more appropriate (e.g. Exec=sh -c "conky -c \"/home/\$USER/.conky/Green Apple Desktop/Gotham1\"" but you’ll need to test/adjust)

By default environment variables do not seem to be resolved by all implementations, however you can instead exec sh, which will resolve the passed environment variable. Note that the desktop spec also requires you to escape the = and $ character with a backslash. So you want:

Exec=sh -c "myprogram --folder\=\$HOME/.special"

For the full list of characters that need escaping, see the specification

thank you, that works for Manjaro XFCE, but see below …

journalctl -b -p err complains:

14 10:56:09 manjaro systemd-xdg-autostart-generator[846]:/home/john1/.config/autostart/conky.desktop:4: Undefined escape sequence \"

But it works, so i don’t care!

p.s. escaping and these ’ ´ ` " is still a mystery for me … i love pascal !

mpf … but it does not work for Linux Mint 20.3

There journalctl -b -p err tells me ( if that is the correct line? )

Apr 14 11:00:44 XPS cinnamon-session[1092]: GLib-CRITICAL: t+9,46484s: unquote_string_inplace: assertion 'err == NULL || *err == NULL' failed

Next step …

Placed a starter-object on Linux Mint 20.3 cinnamon Desktop with this content:

[Desktop Entry]
Exec=sh -c "conky -c \\"/home/\\$USER/.conky/Green Apple Desktop/Gotham1\\""

… and moved it to ~/.config/autostart and that works for Linux Mint 20.3 cinnamon

but this one from Manjaro in ~/.config/autostart in Linux Mint 20.3 cinnamon

[Desktop Entry]
# Exec=conky -c "/home/john1/.conky/Green Apple Desktop/Gotham1"
Exec=sh -c "conky -c \"/home/\$USER/.conky/Green Apple Desktop/Gotham1\""

Will not work

No, at the moment i don’t want to search for the reason … found a solution :slight_smile:

#!/usr/bin/env bash
export ROOT=$(dirname "$(readlink -f "${0}")")
echo "$(cat <<EOF
[Desktop Entry]
)" > $HOME/.local/share/applications/conky.desktop

conky -c "$HOME/.conky/Green Apple Desktop/Gotham1"

Save it somewhere and make it executable. Then run it once from the terminal and it will create a desktop file and run the command. Now you can also run it with the desktop file. Every time you run it, it will update the desktop file, so that you don’t have to deal with variables in the desktop file. Kinda automated self-update of the path.

That probably means you don’t need to escape the $ (if it’s within the quotes) - so just escape the quotes - try and see if complains. LinuxMint wise, different escaping, not sure.

Thanks for your script, but if i start in Manjaro menue, i get this error: ist your code.

I’ll keep my working solution ( that i don’t understand in respect of Linux Mint 20.3 cinnamon )

Next step …

If i take the *,desktop that is working for Linux Mint cinnamon and run it too in Manjaro XFCE … they work both … done :slight_smile:

Sorry, I should know better. Never copy and paste from a script without testing it. Corrected it:


You are right, you don’t need to escape the $, neither in Manjaro nor Mint!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.