9

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.
miyalys
  • 172
  • 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 09 '21 at 10:50
  • 1
    https://askubuntu.com/q/1305382/739431 – PRATAP Feb 09 '21 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 09 '21 at 11:03
  • See https://askubuntu.com/a/1264333/66509 . And simply do not use ill-designed degrading GNOME sHell for real work. – N0rbert Feb 09 '21 at 18:06
  • 1
    https://gitlab.gnome.org/GNOME/nautilus/-/issues/1162 – sancho.s ReinstateMonicaCellio Mar 18 '21 at 17:04
  • 1
    https://askubuntu.com/questions/1187934/cannot-launch-desktop-files-opens-with-text-editor-instead#comment2049008_1187941 ... and the rest of the OP/answers – sancho.s ReinstateMonicaCellio Mar 18 '21 at 17:05
  • Thanks for the links! Here's a hint as to how it's handled for anyone who wants to explore it further. Not my discovery. Maybe, just maybe, allowing it to be launched can be done via this API?: https://sources.debian.org/src/gnome-shell-extension-desktop-icons/20.04.0+git20200908-5/fileItem.js/#L913 Another avenue I've wondered about is modifying dconf, but again, could be another dead end. gnome-shell must do a lookup in some kind of database, and maybe a way to modify that can be found. – miyalys Mar 18 '21 at 19:03
  • Not enough for a separate answer but in case anyone reads the comments gnome-desktop-item-edit used to be a part of gnome-panel and it can be downloaded from e.g. the Ubuntu 18.04 repository, and once you also get the library it depends on - libgnome-desktop you can unpack both and launch it even in 20.10 like this: LD_LIBRARY_PATH="~/Downloads/libgnome-desktop-3-17_3.28.2-0ubuntu1.3_amd64/usr/lib/x86_64-linux-gnu" ./gnome-desktop-item-edit ~/Desktop/ --create-new ...BUT there's little point, because it's still not launchable, so it was a dead end. See Hasan's answer instead! – miyalys Mar 23 '21 at 18:49
  • See also: https://stackoverflow.com/questions/60074557/gnome-3-and-desktop-files-what-exactly-does-allow-disallow-lauching-do – miyalys Mar 29 '21 at 14:48

1 Answers1

8

PiluX v1.0 (An Ubuntu 22.04 based OS, Not released yet), is used this script for trust all desktop icons ( /bin/teteosnet/trustdesktop all )

#!/bin/bash
cd $(xdg-user-dir DESKTOP)

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

chmod +x *.desktop

It's mean using this code is good idea for trust just one .desktop file:

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

Note: trusted yes is wrong , use trusted true

Wrong: gio set ..desktop metadata::trusted yes

Correct: gio set ..desktop metadata::trusted true

Good luck :)

Hasan Merkit
  • 463
  • 2
  • 10
  • 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?: https://askubuntu.com/questions/1187934/cannot-launch-desktop-files-opens-with-text-editor-instead#comment2049008_1187941 – miyalys Mar 20 '21 at 07: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 '21 at 20:16