How can I use terminal commands to access Ubuntu menu items?












1















I need to run a bash script that will retrieve all of the desktop files located in a specific menu item (like accessories/utilities or education, etc) and then run a specific one of them. What terminal commands can I use to do this?










share|improve this question





























    1















    I need to run a bash script that will retrieve all of the desktop files located in a specific menu item (like accessories/utilities or education, etc) and then run a specific one of them. What terminal commands can I use to do this?










    share|improve this question



























      1












      1








      1








      I need to run a bash script that will retrieve all of the desktop files located in a specific menu item (like accessories/utilities or education, etc) and then run a specific one of them. What terminal commands can I use to do this?










      share|improve this question
















      I need to run a bash script that will retrieve all of the desktop files located in a specific menu item (like accessories/utilities or education, etc) and then run a specific one of them. What terminal commands can I use to do this?







      command-line scripts menu .desktop execute-command






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 8 at 13:01









      dessert

      25.3k673107




      25.3k673107










      asked Feb 8 at 4:46









      tristotristo

      1083




      1083






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The .desktop files are located under either /usr/share/applications/ (system wide) or ~/.local/share/applications (per user). The categorisation is done by setting the “Categories” property in the file and this may not be the exact same as shown in the menu, so you first need to find out the correct category name. In my menu there’s a category called “Büro”, which is the German term for “Office”, and it contains a launcher for qpdfview. To review the .desktop file’s “Categories” line I run:



          $ grep Categories /usr/share/applications/qpdfview.desktop 
          Categories=Viewer;Office;


          That shows the two categories for the program, so it’s called “Office” in the .desktop files. To get a list of every .desktop file categorised with “Office” I use grep again, with the -l flag to only show filenames without matches:



          $ grep -l Categories.*Office /usr/share/applications/*
          /usr/share/applications/evince.desktop
          /usr/share/applications/evince-previewer.desktop
          /usr/share/applications/gnucash.desktop
          /usr/share/applications/libreoffice-base.desktop
          /usr/share/applications/libreoffice-calc.desktop
          /usr/share/applications/libreoffice-draw.desktop
          /usr/share/applications/libreoffice-impress.desktop
          /usr/share/applications/libreoffice-math.desktop
          /usr/share/applications/libreoffice-startcenter.desktop
          /usr/share/applications/libreoffice-writer.desktop
          /usr/share/applications/qpdfview.desktop


          So that’s our list of office programs, now to run them I’d simply use xdg-open, e.g.:



          xdg-open /usr/share/applications/qpdfview.desktop


          If xdg-open doesn’t work on your system you may also just extract the start command from the file and run it directly, e.g.:



          exec $(grep -Po 'Exec=K[^ ]*' /usr/share/applications/qpdfview.desktop)


          You didn’t provide information on how you or the script’s user should choose the program to run, so here are some links that may help you with that:




          • How can I create a select menu in a shell script?

          • Create bash menu based on file list (map files to numbers)


          Saving the filenames in an array for easy processing in a script is as easy as that:



          options=("$(grep -l Categories.*Office /usr/share/applications/*)")





          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%2f1116567%2fhow-can-i-use-terminal-commands-to-access-ubuntu-menu-items%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














            The .desktop files are located under either /usr/share/applications/ (system wide) or ~/.local/share/applications (per user). The categorisation is done by setting the “Categories” property in the file and this may not be the exact same as shown in the menu, so you first need to find out the correct category name. In my menu there’s a category called “Büro”, which is the German term for “Office”, and it contains a launcher for qpdfview. To review the .desktop file’s “Categories” line I run:



            $ grep Categories /usr/share/applications/qpdfview.desktop 
            Categories=Viewer;Office;


            That shows the two categories for the program, so it’s called “Office” in the .desktop files. To get a list of every .desktop file categorised with “Office” I use grep again, with the -l flag to only show filenames without matches:



            $ grep -l Categories.*Office /usr/share/applications/*
            /usr/share/applications/evince.desktop
            /usr/share/applications/evince-previewer.desktop
            /usr/share/applications/gnucash.desktop
            /usr/share/applications/libreoffice-base.desktop
            /usr/share/applications/libreoffice-calc.desktop
            /usr/share/applications/libreoffice-draw.desktop
            /usr/share/applications/libreoffice-impress.desktop
            /usr/share/applications/libreoffice-math.desktop
            /usr/share/applications/libreoffice-startcenter.desktop
            /usr/share/applications/libreoffice-writer.desktop
            /usr/share/applications/qpdfview.desktop


            So that’s our list of office programs, now to run them I’d simply use xdg-open, e.g.:



            xdg-open /usr/share/applications/qpdfview.desktop


            If xdg-open doesn’t work on your system you may also just extract the start command from the file and run it directly, e.g.:



            exec $(grep -Po 'Exec=K[^ ]*' /usr/share/applications/qpdfview.desktop)


            You didn’t provide information on how you or the script’s user should choose the program to run, so here are some links that may help you with that:




            • How can I create a select menu in a shell script?

            • Create bash menu based on file list (map files to numbers)


            Saving the filenames in an array for easy processing in a script is as easy as that:



            options=("$(grep -l Categories.*Office /usr/share/applications/*)")





            share|improve this answer






























              0














              The .desktop files are located under either /usr/share/applications/ (system wide) or ~/.local/share/applications (per user). The categorisation is done by setting the “Categories” property in the file and this may not be the exact same as shown in the menu, so you first need to find out the correct category name. In my menu there’s a category called “Büro”, which is the German term for “Office”, and it contains a launcher for qpdfview. To review the .desktop file’s “Categories” line I run:



              $ grep Categories /usr/share/applications/qpdfview.desktop 
              Categories=Viewer;Office;


              That shows the two categories for the program, so it’s called “Office” in the .desktop files. To get a list of every .desktop file categorised with “Office” I use grep again, with the -l flag to only show filenames without matches:



              $ grep -l Categories.*Office /usr/share/applications/*
              /usr/share/applications/evince.desktop
              /usr/share/applications/evince-previewer.desktop
              /usr/share/applications/gnucash.desktop
              /usr/share/applications/libreoffice-base.desktop
              /usr/share/applications/libreoffice-calc.desktop
              /usr/share/applications/libreoffice-draw.desktop
              /usr/share/applications/libreoffice-impress.desktop
              /usr/share/applications/libreoffice-math.desktop
              /usr/share/applications/libreoffice-startcenter.desktop
              /usr/share/applications/libreoffice-writer.desktop
              /usr/share/applications/qpdfview.desktop


              So that’s our list of office programs, now to run them I’d simply use xdg-open, e.g.:



              xdg-open /usr/share/applications/qpdfview.desktop


              If xdg-open doesn’t work on your system you may also just extract the start command from the file and run it directly, e.g.:



              exec $(grep -Po 'Exec=K[^ ]*' /usr/share/applications/qpdfview.desktop)


              You didn’t provide information on how you or the script’s user should choose the program to run, so here are some links that may help you with that:




              • How can I create a select menu in a shell script?

              • Create bash menu based on file list (map files to numbers)


              Saving the filenames in an array for easy processing in a script is as easy as that:



              options=("$(grep -l Categories.*Office /usr/share/applications/*)")





              share|improve this answer




























                0












                0








                0







                The .desktop files are located under either /usr/share/applications/ (system wide) or ~/.local/share/applications (per user). The categorisation is done by setting the “Categories” property in the file and this may not be the exact same as shown in the menu, so you first need to find out the correct category name. In my menu there’s a category called “Büro”, which is the German term for “Office”, and it contains a launcher for qpdfview. To review the .desktop file’s “Categories” line I run:



                $ grep Categories /usr/share/applications/qpdfview.desktop 
                Categories=Viewer;Office;


                That shows the two categories for the program, so it’s called “Office” in the .desktop files. To get a list of every .desktop file categorised with “Office” I use grep again, with the -l flag to only show filenames without matches:



                $ grep -l Categories.*Office /usr/share/applications/*
                /usr/share/applications/evince.desktop
                /usr/share/applications/evince-previewer.desktop
                /usr/share/applications/gnucash.desktop
                /usr/share/applications/libreoffice-base.desktop
                /usr/share/applications/libreoffice-calc.desktop
                /usr/share/applications/libreoffice-draw.desktop
                /usr/share/applications/libreoffice-impress.desktop
                /usr/share/applications/libreoffice-math.desktop
                /usr/share/applications/libreoffice-startcenter.desktop
                /usr/share/applications/libreoffice-writer.desktop
                /usr/share/applications/qpdfview.desktop


                So that’s our list of office programs, now to run them I’d simply use xdg-open, e.g.:



                xdg-open /usr/share/applications/qpdfview.desktop


                If xdg-open doesn’t work on your system you may also just extract the start command from the file and run it directly, e.g.:



                exec $(grep -Po 'Exec=K[^ ]*' /usr/share/applications/qpdfview.desktop)


                You didn’t provide information on how you or the script’s user should choose the program to run, so here are some links that may help you with that:




                • How can I create a select menu in a shell script?

                • Create bash menu based on file list (map files to numbers)


                Saving the filenames in an array for easy processing in a script is as easy as that:



                options=("$(grep -l Categories.*Office /usr/share/applications/*)")





                share|improve this answer















                The .desktop files are located under either /usr/share/applications/ (system wide) or ~/.local/share/applications (per user). The categorisation is done by setting the “Categories” property in the file and this may not be the exact same as shown in the menu, so you first need to find out the correct category name. In my menu there’s a category called “Büro”, which is the German term for “Office”, and it contains a launcher for qpdfview. To review the .desktop file’s “Categories” line I run:



                $ grep Categories /usr/share/applications/qpdfview.desktop 
                Categories=Viewer;Office;


                That shows the two categories for the program, so it’s called “Office” in the .desktop files. To get a list of every .desktop file categorised with “Office” I use grep again, with the -l flag to only show filenames without matches:



                $ grep -l Categories.*Office /usr/share/applications/*
                /usr/share/applications/evince.desktop
                /usr/share/applications/evince-previewer.desktop
                /usr/share/applications/gnucash.desktop
                /usr/share/applications/libreoffice-base.desktop
                /usr/share/applications/libreoffice-calc.desktop
                /usr/share/applications/libreoffice-draw.desktop
                /usr/share/applications/libreoffice-impress.desktop
                /usr/share/applications/libreoffice-math.desktop
                /usr/share/applications/libreoffice-startcenter.desktop
                /usr/share/applications/libreoffice-writer.desktop
                /usr/share/applications/qpdfview.desktop


                So that’s our list of office programs, now to run them I’d simply use xdg-open, e.g.:



                xdg-open /usr/share/applications/qpdfview.desktop


                If xdg-open doesn’t work on your system you may also just extract the start command from the file and run it directly, e.g.:



                exec $(grep -Po 'Exec=K[^ ]*' /usr/share/applications/qpdfview.desktop)


                You didn’t provide information on how you or the script’s user should choose the program to run, so here are some links that may help you with that:




                • How can I create a select menu in a shell script?

                • Create bash menu based on file list (map files to numbers)


                Saving the filenames in an array for easy processing in a script is as easy as that:



                options=("$(grep -l Categories.*Office /usr/share/applications/*)")






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 8 at 13:59

























                answered Feb 8 at 7:59









                dessertdessert

                25.3k673107




                25.3k673107






























                    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%2f1116567%2fhow-can-i-use-terminal-commands-to-access-ubuntu-menu-items%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

                    Questions related to Moebius Transform of Characteristic Function of the Primes

                    List of scandals in India

                    Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?