Hoping someone smarter than me can help me...

Launchers on my desktop (.desktop) files lose permission to be executable every time I make major changes to my OS, such as my upgrade to 18.04 (Bionic Beaver) or changing windowing manager (Gnome). After these changes,double clicking each icon provided by a launcher file, for example, audacity.desktop results in a message pop up requesting that I "Trust and Launch" the application. Very inconvenient for me because I have loads of launchers well organized in various folders on the desktop based on what I may be developing (Website design versus printed desktop publishing or multimedia editing and DVD creation, etc.) I should not have to open each application from the launchers, click "Trust and Launch", then close it just to make sure it works later when I really need it. Therefore, I have written a simple BASh script to process all the launchers in a given folder, starting with the ~Desktop/ folder itself, but for some weird reason, it just won't work! Here is my production script which doesn't work:

for myDesktop in $HOME/Desktop/*.desktop
do /usr/bin/gio set \"$myDesktop\" \"metadata::trusted\" "yes"

I end up getting these errors instead of the desired result:

gio: Too many arguments
Set a file attribute of LOCATION.
  -t, --type=TYPE             Type of the attribute
  -n, --nofollow-symlinks     Don’t follow symbolic links
[2]+  Done                    for myDesktop in $HOME/Desktop/*.desktop;
    /usr/bin/gio set \"$myDesktop\" \"metadata::trusted\" "yes";

Here is my simulation script which produces the desired output with echo, that is, the desired commands per launcher is simply printed, NOT EXECUTED:

for myDesktop in $HOME/Desktop/*.desktop
do echo /usr/bin/gio set \"$myDesktop\" \"metadata::trusted\" "yes"

The commands created by my simulation prints all the commands for each launcher as needed correctly, for example:

/usr/bin/gio set "/home/bruce/Desktop/audacity.desktop" "metadata::trusted" yes

Copying the command above and running it by itself has the desired effect, in this case, audacity launches as "Trust and Launch", but having to run each command at at the cli every single launcher is even less convenient than just double clicking on each launcher icon and then clicking "Trust and Launch" ... back to square one! Note: Filenames must be quoted because some applications, such as gedit have launchers like "Text Editor.desktop" with spaces in them.

I don't understand why I can get the script to print the correct command for "Trust and Launch" on each *.desktop launcher but BASh refuses to actually run them (after removing the echo command). I have never seen anything like that before, simulation works, but the actual script consistently fails.


Thanks in advance

  • 2
    try removing all backslashes \
    – nosklo
    Mar 21, 2019 at 0:34
  • Backslashes are necessary when using echo but are not necessary when executing the exact command. You do, however, need double quotation marks for the files that contain blank spaces.
    – mchid
    Mar 21, 2019 at 4:27
  • Wow! AskUbuntu is a really great community! Thank you all for your advice because ... well, it worked! I noticed one odd "feature", I had to close out nautilus (my favorite file manager) before I could see changes or else, I still got the pop up "Trust and Launch" whenever I double click a .desktop file modified by my script. I am not just a computer geek, but an old one and I learned a long time ago that things rarely ever works 100% as expected. For best results, I probably should either log out or restart my box. Mar 21, 2019 at 18:54

1 Answer 1


As @nosklo pointed out, removing the backslashes will work.

You do not need back-slashes before the double-quotation marks used to define a variable that may contain blank spaces.

Additionally, the echo command does need backslashes but your bash script does not.

for myDesktop in $HOME/Desktop/*.desktop
do /usr/bin/gio set "$myDesktop" "metadata::trusted" "yes"

To verify your changes, run the following command:

gio info ~/Desktop/*.desktop | grep -P 'metadata|uri'

Files containing a blank space will contain "%20" instead of the blank space in the output of the last command.

Finally, log out and then log back in for your changes to take effect.

Also, if you just want to set these files as executable, then you can use the chmod command like this instead:

for i in ~/Desktop/*.desktop
do chmod +x "$i"

However, this will not make the files "trusted".

  • mchid, Thank you for pointing out the difference between having to quote or escape text strings when using echo versus actually running a command. I really appreciate your advice and will keep that in mind next time I dare to write a "simple script". Mar 21, 2019 at 18:57
  • @BruceE.Reed You are welcome. Don't forget to click the icon to the left to accept this as the chosen solution if this fixes your problem. Thanks!
    – mchid
    Mar 24, 2019 at 2:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .