Skip to content
Advertisement

Installed .desktop file to have user’s home directory path inserted

Wording the title was a little tricky, but here’s the situation. I am making a install.sh file for my game which is written in Python. I am trying to create a game folder with all assets instead of making this a module for Python. I may be doing things the hard way, but this method seems to work well.

The install.sh copies the game’s directory to the HOME folder and moves a .desktop file and game’s icon to the appropriate places (ie. desktop, applications folder). The issue is, this .desktop file uses Icon=~/.local/share/icons/game.png and Exec=~/Game/game.sh which causes the icon not to show up in the .desktop file or menu nor does the game shortcut execute. I replaced the ~ with $HOME and I get the same issue. However, if I change it to /home/(my account) instead of ~ or $HOME it will work perfectly and show the icon.

Is there a way to make the install bash file create this .desktop file dynamically if a user installs the game? Or is there some way of getting this to work that I am unaware of?

EDIT: Better explanation… ish.

Advertisement

Answer

Alternatively, put ~/.local/share/applications in the premade .desktop file, and then sed 's/~/$HOME/g' appname.desktop > $HOME/.local/share/applications/appname.desktop in the installer script, or invoke that from your language interpreter as a shell exec.

It’s a real shame that more projects with GUIs don’t do this. These desktop files also need a ‘wmClass’ element in them in order to allow for the launcher to also be a window tab. I’ve manually fixed several applications for my convenience this way.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement