Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 422  / 2 Years ago, sun, february 6, 2022, 6:11:21

i have this bash script: test.sh that i would like to be able to find in my apps and/or as a favorite in my dock.


since i've never done that i relied on:
Execute sh script from *.desktop file?


i then created a file: test.desktop


[Desktop Entry]
Name=TEST
Comment=bash copy/resize
Exec=bash ~/mybash/test.sh
NoDisplay=False
Terminal=False
Type=Application
Icon=~/usr/share/pixmaps/copy-resize.png
Categories=Accessories;

set permission to execute, and created /usr/share/applications, /usr/share/pixmaps and /mybash in my home directory to start with.
I could right click it and run as application, but it was not visible in settings>applications


dragging it to the desktop didn't help, so found:
Cannot launch .desktop files (opens with Text Editor instead)


since i did not know how to find the /.local folder i decided to copy the file:


sudo cp ~/usr/share/applications/test.desktop ~/.local/share/applications

It now can be found under settings>applications alas it is listed without the icon but i cannot find it under apps.
If i search in the app view (9 dots) i find the /.local/share/applications/test.desktop listed as a text file and right clicking does not give me the option to set it to favorites and left it opens in geany (as it was made with that app)


if i try in a terminal:


bash ~/.local/share/applications/test.desktop

it starts the sh script, output in terminal:


/home/maarten/.local/share/applications/test.desktop: 1: [Desktop: not found
/home/maarten/.local/share/applications/test.desktop: 3: Cam: not found
starting gui...

and that does it's job, in the dock I see the icon I choose and a dot that it's active and the gui opens.
so except for the icon location in settings>applications this part works.
But double clicking still leads to the text editor.
If placed on the desktop i can set 'allow launching' changing the file icon to a text document, but then double click does nothing.


the big question is Who can fill me in on what i missed in making this work?


At this moment i've copied test.desktop to:


(home)/test.desktop, (with/without allow launching)
/Desktop/test.desktop,
/.local/share/applications/test.desktop and
/usr/share/applications/test.desktop.

on all placed i can use a rightclick and choose to run as program, but nowhere does a double click lead to opening the file.


More From » bash

 Answers
3

Quick-Fix


Try the steps below



  1. Change your .desktop file by replacing ~/some/path/file.ext to /home/<username>/some/path/file.ext



  2. You can also set Terminal=True to open a terminal when running the .desktop shortcut.


    Your .desktop file should look like this:


    [Desktop Entry]
    Name=TEST
    Comment=bash copy/resize
    Exec=bash /home/<your-username>/mybash/test.sh
    NoDisplay=False
    Terminal=True
    Type=Application
    Icon=/usr/local/share/pixmaps/copy-resize.png
    Categories=Accessories;



Expected Behavior w/ Screenshots



  • When viewing .desktop files in a File browser like Nautilus, the files will appear like typical text files or potentially with gear symbols on them
    enter image description here



  • When double-clicking on a .desktop file the default file action set for that mime-type in xdg-settings will be applied, in this case the .desktop file will open in your default text-editor
    enter image description here

     
    you can check your xdg-mime settings like this:
    enter image description here


    As you can see, my default is GNOME Builder too



 



  • I've been showing the above using the JetBrains CLion IDE .desktop file, now let me show you how to properly utilize the .desktop file.

    1. first access your application menu with Super/Win key on your keyboard, or by clicking on the 3x3 grid icon on your taskbar [note: this can differ depending on your desktop environment and your configuration]
      enter image description here



    2. start typing your application name; in your case TEST but in my example CLion
      enter image description here






Info



  1. it's already been pointed out that using the ~ shortcut doesn't work inside a Unity Launcher .desktop file


    which is why you need to specify the full path to your script and its icon file



  2. you should use either /home/<username>/.local/share/applications/ for just your user account to see the entry

    or /usr/local/share/applications/ for all users of the machine to see the entry



  3. you don't need a $HOME/usr/ folder, $HOME/.local/ is probably what you were thinking of



  4. refer here for more details about how to properly setup a .desktop launcher file




References


Unity Launcher Specification

Ubuntu-desktop command manual


[#684] Monday, February 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
serveeel

Total Points: 347
Total Questions: 106
Total Answers: 117

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
serveeel questions
Tue, Nov 23, 21, 11:26, 3 Years ago
Thu, Jan 13, 22, 12:38, 2 Years ago
Sat, Oct 9, 21, 04:32, 3 Years ago
;