Simple Bash Script To Set All Launchers (*.desktop) To Executable Doesn't Work












1















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:



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


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



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


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



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


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.



Help!



Thanks in advance










share|improve this question


















  • 2





    try removing all backslashes

    – nosklo
    1 hour ago













  • Also, you don't need to use echo.

    – mchid
    47 mins ago
















1















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:



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


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



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


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



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


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.



Help!



Thanks in advance










share|improve this question


















  • 2





    try removing all backslashes

    – nosklo
    1 hour ago













  • Also, you don't need to use echo.

    – mchid
    47 mins ago














1












1








1








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:



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


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



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


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



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


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.



Help!



Thanks in advance










share|improve this question














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:



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


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



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


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



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


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.



Help!



Thanks in advance







bash scripts .desktop






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Bruce E. ReedBruce E. Reed

263




263








  • 2





    try removing all backslashes

    – nosklo
    1 hour ago













  • Also, you don't need to use echo.

    – mchid
    47 mins ago














  • 2





    try removing all backslashes

    – nosklo
    1 hour ago













  • Also, you don't need to use echo.

    – mchid
    47 mins ago








2




2





try removing all backslashes

– nosklo
1 hour ago







try removing all backslashes

– nosklo
1 hour ago















Also, you don't need to use echo.

– mchid
47 mins ago





Also, you don't need to use echo.

– mchid
47 mins ago










1 Answer
1






active

oldest

votes


















0














As @nosklo pointed out, removing the backslashes will work. However, you need to also remove the echo command (echo is also not needed).



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 will only "echo" what you ask it to say and does not execute what follows and so /usr/bin/gio is not executed when echo is used.



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


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.





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



#!/bin/bash
for i in ~/Desktop/*.desktop
do chmod +x "$i"
done


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






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1127393%2fsimple-bash-script-to-set-all-launchers-desktop-to-executable-doesnt-work%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As @nosklo pointed out, removing the backslashes will work. However, you need to also remove the echo command (echo is also not needed).



    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 will only "echo" what you ask it to say and does not execute what follows and so /usr/bin/gio is not executed when echo is used.



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


    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.





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



    #!/bin/bash
    for i in ~/Desktop/*.desktop
    do chmod +x "$i"
    done


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






    share|improve this answer






























      0














      As @nosklo pointed out, removing the backslashes will work. However, you need to also remove the echo command (echo is also not needed).



      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 will only "echo" what you ask it to say and does not execute what follows and so /usr/bin/gio is not executed when echo is used.



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


      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.





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



      #!/bin/bash
      for i in ~/Desktop/*.desktop
      do chmod +x "$i"
      done


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






      share|improve this answer




























        0












        0








        0







        As @nosklo pointed out, removing the backslashes will work. However, you need to also remove the echo command (echo is also not needed).



        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 will only "echo" what you ask it to say and does not execute what follows and so /usr/bin/gio is not executed when echo is used.



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


        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.





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



        #!/bin/bash
        for i in ~/Desktop/*.desktop
        do chmod +x "$i"
        done


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






        share|improve this answer















        As @nosklo pointed out, removing the backslashes will work. However, you need to also remove the echo command (echo is also not needed).



        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 will only "echo" what you ask it to say and does not execute what follows and so /usr/bin/gio is not executed when echo is used.



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


        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.





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



        #!/bin/bash
        for i in ~/Desktop/*.desktop
        do chmod +x "$i"
        done


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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 44 mins ago

























        answered 1 hour ago









        mchidmchid

        23.3k25286




        23.3k25286






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1127393%2fsimple-bash-script-to-set-all-launchers-desktop-to-executable-doesnt-work%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            GameSpot

            connect to host localhost port 22: Connection refused

            Getting a Wifi WPA2 wifi connection