Creating a program shortcut on the desktop entirely from the terminal (CLI)? - Ubuntu 20.04 / GNOME 3

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.

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 :)