After moving a .desktop file into the "Desktop" location ~/Desktop, it show the icon on the Desktop. For the first run you have to trust the application. Is there any way to trust it directly without clicking? chmod +x *.Desktop is already done to make the file executable

enter image description here

  • 1
    Sorry my solution only works on KDE, but I found this older solution which may still work in bionic, though it would still be more work than simply using the trust dialog for less than the number of new .desktop entries you find inconvenient askubuntu.com/questions/969231/… – nobody special Aug 29 at 13:02
up vote 3 down vote accepted

With thanks to nobody special, desktop files can be trusted via command line: gio set Your_desktop_file.desktop "metadata::trusted" yes

NOTE:

  • You have to run this command with the same user as the owner of the desktop files
  • It only works if you run the command in the gnome shell (not via SSH)
  • To do this automatically at logon, you have to make a logon script what will execute an script, as this only run when Gnome is started. For example you can create an .desktop file in ~/.config/autostart/ what execute some shell script including the gio commands
  • Make sure nautilus-desktop is really started. You can create an while loop with a sleep 1 till nautilus-desktop run
  • Icon's will not refresh automatically. You can achieve this with pressing F5 on the desktop or restart nautilus in your autostart script. killall nautilus && nautilus-desktop & (the last & sign is to make sure the rest of your code will run. Otherwise it will stop the script there till you close nautilus-desktop process again)
  • Awesome, glad it worked for you :) – nobody special Aug 29 at 13:57
  • I have been looking for something like this for awhile so thanks to you both! However, I ran into a couple issues. First, the metadata file (~/.local/share/gvfs-metadata/home) was owned by root instead of my user for some reason. I used chown to fix that. However, now I get an error "gio: Unable to set metadata key". Still looking for a solution for this. – ajh158 Sep 24 at 21:40
  • This happen when you run this script in another user. It have to run with the same owner and also really in gnome interface (or autostart). It is usefull when you run this for .desktop files located in ~/Desktop. – Sander Sep 25 at 21:09

You have to make the .desktop files executable (trust), which you can do by going to ~/Desktop in a terminal and issue the following command

chmod u+x foo*

Obviously use a wildcard suitable for your needs, then refresh your desktop. That would be more effort than the trust mechanism for a single entry, but save time if you imported say more than n entries (where n is your number of max inconvenience).

There are ways of monitoring the directory and automatically doing this with external tools but I would advise you to seriously consider the security implication of doing such a thing.

But there is no way of doing this within your DE that I am aware of.

NOTE: This works on KDE but apparently does not work on Gnome.

  • It's not that I can not execute them. If I don't make it "trusted" with the chmod you are suggesting, I am not able at all to open the .desktop file. After I have done the chmod +x I still need to click on every single entry on the Desktop and click on the button "trust". I have edited my question and added an image. – Sander Aug 29 at 11:56
  • @Sander Oh, that's different to what I get, which is why I suggested that solution. I get a dialog showing me the command that will be run, asking if I want to run the application on first execution. After clicking continue, I never get the dialog again. But if I pre set the execution permission on the .desktop file, then I do not get the dialog on first or subsequent executions, it is simply trusted. Seems gnome and kde have different ideas about trust, I thought it was a Ubuntu mechanism and as such would be the same across DEs. – nobody special Aug 29 at 12:39
  • Ah, you are using kde. Guess that this must be a difference then, yes. After you make it executable with chmod +x *.desktop it ask this question. When you click once on "Trust and Launch" it will work forever. It's just the first time. Looking forward for the special trick! Thank you anyway :-) – Sander Aug 29 at 13:04
  • @Sander found an old post that has a cli trick in it which I put in a comment under your question, maybe that will do it for you, wish you luck in your quest :) – nobody special Aug 29 at 13:08

Inspired by the great answer of @Sander, i am quite happy with this approach in Ubuntu 18.04. I use this in an automated VM creation setup, where first the desktop icons are placed, and then these scripts are prepared. They are only executed at the first start.

I create a desktop file ~/.config/autostart/desktop-truster.desktop with the following content:

[Desktop Entry]
Name=Desktop-Truster
Comment=Autostarter to trust all desktop files
Exec=~/.config/autostart/desktop-truster.sh
Type=Application

Next to it, a script ~/.config/autostart/desktop-truster.sh, which is invoked by the autostart desktop file:

#!/bin/bash
# Wait for nautilus-desktop
while ! pgrep -f 'nautilus-desktop' > /dev/null; do
  sleep 1
done
# Trust all desktop files
for i in ~/Desktop/*.desktop; do
  [ -f "${i}" ] || break
  gio set "${i}" "metadata::trusted" yes
done
# Restart nautilus, so that the changes take effect (otherwise we would have to press F5)
killall nautilus-desktop && nautilus-desktop &
# Remove X from this script, so that it won't be executed next time
chmod -x ${0}
  • Exactly like this, good job @Janos Only thing when you remove the X from itself it will not run this anymore in case you put new icons in – Sander Nov 28 at 15:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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