How can I use terminal commands to access Ubuntu menu items?
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
add a comment |
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
add a comment |
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
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
command-line scripts menu .desktop execute-command
edited Feb 8 at 13:01
dessert
25.3k673107
25.3k673107
asked Feb 8 at 4:46
tristotristo
1083
1083
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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/*)")
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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/*)")
add a comment |
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/*)")
add a comment |
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/*)")
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/*)")
edited Feb 8 at 13:59
answered Feb 8 at 7:59
dessertdessert
25.3k673107
25.3k673107
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
