8

Has a way to create a program shortcut on the desktop entirely from the terminal / CLI (scriptable) been discovered in Ubuntu 20.04?

I can copy in .desktop files from /usr/share/applications/, and set them as executable, but apparently that's no longer enough. There is now a final step:

Right-click the shortcut -> Select Allow Launching.

Until that is done, double-clicking it simply opens the .desktop file as a text file, rather than execute the program. Furthermore before that step, the icon is the generic shell script icon, rather than the program's own icon.

...and I don't yet know how to do that step from the terminal.

Any help is appreciated - thank you.


My own investigations:

Allow Launching does set the script as executable, but doing that manually is not enough. Also from my investigation it doesn't alter the .desktop file itself, and no changes are made that are visible to ls -l or lsattr, so I'm assuming it's some other database of sorts, that tracks which shortcuts it's allowed to launch and which it isn't?

Considered solutions:

  • gnome-desktop-item-edit can't do it, and it also no longer exists in recent versions of Ubuntu.
  • alacarte I'm unsure about, but regardless it's GUI only.
  • desktop-file-install/desktop-file-edit I'm unsure about.
9
  • 1
    I think its changed in Ubuntu 20.04 or since last few releases.. even you set it as executable via manual way it opens as a text file..
    – PRATAP
    Feb 9, 2021 at 10:50
  • 1
    askubuntu.com/q/1305382/739431
    – PRATAP
    Feb 9, 2021 at 10:52
  • Regarding the suggestion in your link: It will probably not be so pretty / user friendly as I assume it will retain the generic .desktop icon rather than the icon of the program it's launching(?) (that's also something Allow launching fixes), but the idea of creating the file association between .desktop and gtk-launch is interesting, I'll try that out. But there must be a way of performing that Allow launching action from the terminal somehow. Another way of showing the right icon would also be useful though.
    – miyalys
    Feb 9, 2021 at 11:03
  • 1
  • 1
    askubuntu.com/questions/1187934/… ... and the rest of the OP/answers Mar 18, 2021 at 17:05

1 Answer 1

7
+50

Used this script by PiluX v2.0 (Ubuntu 20.04 Custom OS) (It's worked)

Script is trusting all .desktop files in User Desktop folder and setting permissions.

#!/bin/bash
cd $(xdg-user-dir DESKTOP)
chmod +x *.desktop

FILES="*.desktop"
for f in $FILES
do
    gio set $f metadata::trusted true
done

Changing this script like this idea for your app;

#!/bin/bash
gio set $(xdg-user-dir DESKTOP)/app.desktop metadata::trusted true
chmod +x $(xdg-user-dir DESKTOP)/yourapp.desktop

(gio set ...desktop metadata::trusted value to true. Not yes.) Good luck :)

2
  • 1
    Thanks!! So far everything seems to work! I'll wait a few more days to see if people come up with other answers in case the GNOME devs decide to remove gio next time and we need a new way. In the mean time maybe you want to add the answer to this question as well and help some more people + get some additional reputation?: askubuntu.com/questions/1187934/…
    – miyalys
    Mar 20, 2021 at 7:15
  • 1
    On Ubuntu 21.04, it’s necessary to run the gio set $f metadata::trusted true step before doing the chmod +x. For the curious: gio uses glib functionality to store this metadata in binary files inside ~/.local/share/gvfs-metadata.
    – andrew
    Sep 21, 2021 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.