Page 2 of 2

Re: "Open With" Context Menu - Bash Commands

Posted: Sun Feb 20, 2022 3:21 am
by abacus7
Didn't work, but I'll show you what I did.

First I created the script and put it in .local/bin:

Code: Select all

#!bin/bash
echo "Enter keyword" && read keyword && grep -i --color=always "$keyword" "$1"; read
Then I made it executable.

Then I created a desktop file and put it in local/share/applications:

Code: Select all

[Desktop Entry]
Name=grepper
Comment=Grep keyword in selected file
Exec=/home/abacus7/.local/bin/grepper %f
Icon=terminal
Type=Application
Terminal=true 
It showed up under the right click menu but when I selected for a specific file, it opened a blank terminal page.

Re: "Open With" Context Menu - Bash Commands  Topic is solved

Posted: Sun Feb 20, 2022 9:06 am
by abacus7
Success!

The final touch needed was to prepend "bash" to the command line in the desktop file. It hadn't worked when I tried it earlier (directly inputting the grep code into the desktop file), but it works now that I'm referencing a script which contains the grep code.

Here is the final desktop file:

[Desktop Entry]
Name=Grep keyword in selected file
Comment=grepper
Exec=bash /home/abacus7/.local/bin/grepper %f
Icon=terminal
Type=Application
Terminal=true

Thanks for your help.

Re: "Open With" Context Menu - Bash Commands

Posted: Tue Feb 22, 2022 7:05 am
by drooly
This shouldn't be necessary. Did you mark ~/.local/bin/grepper executable, as I pointed out earlier?

Re: "Open With" Context Menu - Bash Commands

Posted: Mon Feb 28, 2022 3:37 am
by abacus7
drooly wrote: Tue Feb 22, 2022 7:05 am This shouldn't be necessary. Did you mark ~/.local/bin/grepper executable, as I pointed out earlier?
Yep, I marked it executable.

A couple of years ago when I was experimenting with scripts and desktop files, I noticed how hard it was to get things to work right. Reading a bunch of StackExchange or AskUbuntu or whatever posts pointed out that adding "bash" was often needed to get script-based desktop files to work. Don't know why this is the case, it's just one of those weird rules that conspires to make things harder for all us. :mrgreen:

Re: "Open With" Context Menu - Bash Commands

Posted: Sat Mar 05, 2022 6:23 am
by drooly
OK. You might want to mark this thread SOLVED now (it should have a green checkmark).