1

Trying to create a .desktop file for a program and it requires a universal username path so instead of Exec=/home/john/myscript.sh it's Exec=/home/$USER/myscript.sh.

in .desktop files you need an exact path and $USER does not work. Neither does $LOGNAME.

.Desktop EXEC universal home path

^This did not work either (the edited solution not the one voted as). Because this solution did not work, it is not relevant to this question.

Not sure what else to try. If someone could chime in it'd help a lot. Thank you.

Here is my desktop file

[Desktop Entry] Type=Application Encoding=UTF-8 Version=1.0 Terminal=false Exec=/bin/bash -c '/home/$USER/mycroft-core/start-mycroft.sh all' Name=Mycroft AI Icon=/usr/share/MycroftIcon/MycroftIcon.jpg X-GNOME-Autostart-enabled=true

Edit: I had a typo in my code the solution provided by @mchild works:

The solution is: Exec=/bin/bash -c '/home/$USER/myscript.sh'

John
  • 73
  • 1
    Why not put myscript.sh in the /usr/local/bin directory? – waltinator Jan 18 '20 at 04:30
  • @waltinator it won't run from /usr/local/bin for some reason. – John Jan 19 '20 at 00:49
  • @vanadium I explicitly said in my initial post that the solution you posted (For some odd reason) did not work. – John Jan 19 '20 at 00:49
  • @mchid I have tried $HOME and it did not work – John Jan 19 '20 at 00:49
  • 1
    Are you sure there is not something else wrong with the desktop file? I tested the solution using Exec=sh -c '$HOME/myscript.sh' and Exec=/bin/bash -c '/home/$USER/myscript.sh' and it worked. Have you tested: Exec=/home/john/myscript.sh to see if that works? If it doesn't execute when you use the full path, you will know that you have a different problem. I tested this on a desktop file in my Desktop directory. I had to right click on the file: > Properties > Permission > check the box for "allow executing as a program". Then, double-click the file on desktop and select to trust. – mchid Jan 19 '20 at 03:05
  • 1
    If this is not a duplicate of the other answer, please post the contents of your desktop file and also please verify that the desktop file will execute when you use the full path: Exec=/home/john/myscript.sh One problem could be that the myscript.sh file is not executable or you could have other lines in your file that are preventing the file from executing. Thanks! – mchid Jan 19 '20 at 03:08
  • @mchild desktop file added to original post. The script works fine as I have been using this desktop file for a while now without the $USER variable. – John Jan 20 '20 at 22:39
  • @mchild the script works fine if I replace $USER with my actual username – John Jan 20 '20 at 22:42
  • @mchild your solution worked, I had a typo in my code. Thanks so much!! – John Jan 20 '20 at 22:45

0 Answers0