Score:0

How to automatically detect username when setting file path for icon

br flag

Im creating a desktop shortcut. I've been playing around with some of the lines and one thing I'm currently stuck at is automatically detecting username for a file path for an icon.

This code works currently but with manual username input in the line. Icon=/home/myusername/Desktop/Icons/test_icon.png

What I'm trying to find out is Icon=/home/**automaticallydetectusername**/Desktop/Icons/test_icon.png

br flag
I tried this earlier but it didn't work ):
hr flag
The only supported way I know of is to place the icons in one of the user-specific default icon search directories ex. `~/.local/share/icons` - see [freedesktop icon theme specification: Directory Layout](https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html). At a pinch, I suppose you could modify `XDG_DATA_DIRS` to include your custom location.
Score:2
cn flag

.desktop files are hardcoded. They do not support bash expansions or variables.

The approach to go about this here is to specify the icon by its file name without extension in the .desktop file, as in:

Icon=myicon

Then have the icon, customized for the user, installed in ~/.local/share/icons or ~/.icons, e.g ~/.local/share/icons.png.

An icon file installed in these user configuration directories will take precedence over systemwide installed icons with the same file name (/usr/local/share/icons, or /usr/share/icons for applications installed using the package management system).

br flag
Got it, thank you for the explanation
vanadium avatar
cn flag
Please consider accepting the question if it answered your issue.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.