Score:0

Desktop (not application menu) icons for all users in Ubuntu 20.04

pr flag

I have a machine running Ubuntu 20.04 and made a .desktop file. I tested it in my desktop and it worked, so i copied it to all existent users and did

sudo su; cd /etc/skel/; mkdir Desktop;
cp /home/MyUser/Desktop/MyIcon.desktop ./

So that all new users have access to the icon (the application is executable by all). However, when looking at what appears to other users, it is clearly not an executable .desktop file (comparison for what appears to my user and other users in images below).

what appears for my user What appears to other users

It seems doing what this answer suggests solves the issue, but i need to be the other_user doing this (where other_user is the user that will have the icon as an executable). So the only thing that can automatize the creation and correct configuration of the icon for new and existent users that comes to my mind is doing:

cd /path/to/other/user/Desktop
sudo su -l OtherUser
gio set app.desktop metadata::trusted true

for existent users and, for new future users:

cd /etc/skel/

and adding

gio set ~/Desktop/app.desktop metadata::trusted true

to .bashrc. This does not feel intelligent. Also, the sudo su -l option returns me an error:

gio: Setting attribute metadata::trusted not supported

Is there a better way for new users and a working way for already existent users?

Edit to add response to cbugk comment: content of file is in the form:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/usr/local/path/to/executable
Name=Name of application
Icon=/usr/local/path/to/image.png
cbugra avatar
br flag
I have seen the duplicate in Unix SE, yet this seems to be the proper place. Could you add content of .desktop file? Edit: This is said to work on for Kali and Gnome, might work: https://stackoverflow.com/a/73455006
Marco Montevechi Filho avatar
pr flag
Thanks, @cbugk! I dont have immediate access to the environment in which i need this to work but i tested it in my ubuntu 22.04 and it worked just like i wanted. I also edited my question to add the file content like you asked. If i test it in ubuntu 20.04 and it works just fine, should i close this question or accept your suggestion as an answer?
Marco Montevechi Filho avatar
pr flag
Update: it worked just as nice in ubuntu 20.04
cbugra avatar
br flag
Glad it worked. You did the work mate, not feeling greedy today :D. Since the link is SO it should not matter but it is a good rule of thumb to link to the sources and reproduce relevant suggestions in case the link breaks in the future. So, I say write down what you have done, and accept your own.
Score:0
pr flag

Answer based on @cbugk comments and the third answer for this question.

For some reason, even switching to user via sudo su -l or sudo su doesnt allow you to allow the launching of the desktop icon via CLI. I guess its some security reason, but not sure. Apparently you can use dbus messages to work around this and send the command indirectly. My way of doing it for several users and several desktop icons:

  1. For all users that already have a desktop:
 cd /home/
 sudo su -l user
 cd Desktop 
 for icon in ./*.desktop; do desktop-file-install --mode=0755 --dir=$HOME/Desktop ~/Desktop/$icon; done;
 for icon in ./*.desktop; do dbus-launch gio set ~/Desktop/Telegram.desktop "metadata::trusted" true; done;
  1. For future users:

cd /etc/skel/

mkdir Desktop; cd Desktop

(copy all my .desktop files to here and add the following lines to /etc/skel/.bashrc)

for file in $HOME/Desktop/*.desktop; do desktop-file-install --mode=0755 --dir=$HOME/Desktop $file; done

for file in $HOME/Desktop/*.desktop; do dbus-launch gio set $file "metadata::trusted" true; done

BE AWARE: item 2 will give permission for all desktop icons in user desktop to be executed every time the user logs in. This might be a security risk. I accept suggestions on better implementations.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.