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

The dedicated forum for PCMan File Manager - http://wiki.lxde.org/en/PCManFM
abacus7
Posts: 29
Joined: Sat Nov 10, 2018 8:17 pm

Re: "Open With" Context Menu - Bash Commands

Post 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.
abacus7
Posts: 29
Joined: Sat Nov 10, 2018 8:17 pm

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

Post 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.
drooly
Posts: 791
Joined: Mon Apr 08, 2013 6:45 am

Re: "Open With" Context Menu - Bash Commands

Post by drooly »

This shouldn't be necessary. Did you mark ~/.local/bin/grepper executable, as I pointed out earlier?
abacus7
Posts: 29
Joined: Sat Nov 10, 2018 8:17 pm

Re: "Open With" Context Menu - Bash Commands

Post 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:
drooly
Posts: 791
Joined: Mon Apr 08, 2013 6:45 am

Re: "Open With" Context Menu - Bash Commands

Post by drooly »

OK. You might want to mark this thread SOLVED now (it should have a green checkmark).
Locked