ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
349 stars 37 forks source link

How to run a simple bash script via ContextSearch #504

Closed ThomasSeeker closed 2 years ago

ThomasSeeker commented 2 years ago

Hello ssborbis,

I would like to run a simple bash script via ContextSearch. I tried to add one via "New Script", but couldn't get it to work.

I tried copying in the whole bash script, ... as well as just inserting the path to the script on my computer.

What am I missing here?

Best greetings, Thomas

ssborbis commented 2 years ago

"Scripts" are for javascript to be run within the current webpage. It's essentially the new "Bookmarklet" type, but without the need to actually save the javascript as a bookmarklet first. Code can be entered directly into the Script edit modal.

"App Launcher" is for running bash scripts, binaries, etc; anything outside the web browser.

You'll need to install the latest python v3 and the native app script. https://github.com/ssborbis/ContextSearch-Native-App

Once python is installed, download the source from the link above and run install.py. Another user reported issues with the latest nativeapp so it's possible there's an issue with the installer. I'll try it myself here in a sec. Once the native app is installed, add a new App Launcher from the context menu like you would a script. You'll probably be prompted to grant the native messaging permission. You should see a message at the bottom of the App Launcher edit modal that says the version of the native app (v2.17). If there's a problem with the connection, it will say "Messenger not connected"

ssborbis commented 2 years ago

There are a few ongoing threads regarding the app launcher you can look through for some ideas also

459

498

ThomasSeeker commented 2 years ago

Wow, that was easy! ... Works like a charm! Thank you very much, for your fast and reliable help, Sborbis!

It is always a pleasure to fine tune ContextSearch even a bit more. :-D So many possibilities ... Wow!

ssborbis commented 2 years ago

Wow, that was easy! ... Works like a charm!

Glad to hear it.

So many possibilities ... Wow!

I'm using it pretty frequently, myself. Thanks goes to karinaardos for the suggestion. It's still a very raw feature in terms of development, so don't hesitate to point out any limitations.

ThomasSeeker commented 2 years ago

I read all the other threads. ... And I am able to load pictures directly to Gimp now (with the new beta-version and the {download_url}-feature). ... What a nice thing! :-)

Now I am trying to open links in Chromium. I copied your command (see in the screenshot) ... but that does not work. ... With the /^$/{url}/g expression I got it to open the whole page (instead of just the link) though. ... which would be the desired outcome for not clicking on a link (but somewhere else).

Unfortunately I have no clue about regex. And I am also not quite sure, if I understand the choices in the top row correctly. I.e. Audio, Frame, Image, Link, etc. Is this a filter to determine, where the app-launcher should be triggered and where not? ... (The tool-tip to the right next to them speaks of "Advanced - Filter Engines" ... but I could not find this option in the Advanced-Menu.)

Do you have some advice?

Screenshot_20220719_150227

7peanuts commented 2 years ago

Now I am trying to open links in Chromium. I copied your command (see in the screenshot) ... but that does not work. ...

You should enter the full Path in the COMMAND field. See the README here 8. Launching External Applications

Examples:

COMMAND "d:\\Program Files\\Opera\\launcher.exe" "{searchTerms}"

or

COMMAND launcher.exe "{searchTerms}" WORKING DIRECTORY D:\Program Files\Opera\

Unfortunately I have no clue about regex. And I am also not quite sure, if I understand the choices in the top row correctly. I.e. Audio, Frame, Image, Link, etc.

This represents on which element types the engine takes effect, and if you check Filter search engines... in the ADVANCED options of the Context Menu or Quick Menu, then the engine will only be displayed on those checked element types.

20220719233729

If you don't select any element type, then by default the engine only works on type selection.

ssborbis commented 2 years ago

@ThomasSeeker

The contexts (audio, video, link, image, etc ... ) refer to HTML element types. As @7peanuts pointed out, these options do nothing unless you enable contextual filtering for the menu you're using. Then, only those engines with the proper context for the HTML element type you're currently selecting ( link for example ), are displayed in the menu.

Is chromium-browser the command you use from a terminal window to launch that app? On my 'nix install, it's just chromium, so my command line is chromium "{searchTerms}".

I'd double-check that, and maybe try using the full command path if necessary, i.e. /path/to/binary/chromium-browser "{searchTerms}"

ThomasSeeker commented 2 years ago

@7peanuts

Thank you for pointing out the Advanced settings! Now I found it and it works great! :-)

Regarding the command, .... I am running Linux and the first part seems right. I am doubting the argument-part.

@ssborbis

Yes, in the terminal I use for instance: chromium-browser https://www.spiegel.de/thema/meinung/ to open this link.

If I use chromium-browser "{searchTerms}"as the command, and click on a that link, it just opens Chromium, but with an empty url and nothing is shown.

But if I use chromium-browser {url} as the command, and click on the link, it opens not the link, but the whole parent-page, i.e. https://www.spiegel.de

ThomasSeeker commented 2 years ago

Ha, I found the problem:

In the general settings I had checked to use links as text instead of url. ... Now it works! :-D

ssborbis commented 2 years ago

@ThomasSeeker

That'll do it. Glad to hear you got it sorted out.

ThomasSeeker commented 2 years ago

This is just a minor thing, ... but would it be possible, to have both: Open Chromium with the link, if one clicks on a link ... AND open Chromium with the parent page, if one clicks everywhere except on a link?

But only, if it is really easy to do, because this is really just a minor thing.

ThomasSeeker commented 2 years ago

I had an idea. I am working on a little bash script, which gets triggered and receives the two arguments "{searchTerms}" "{url}". And the script then decides if the first one is not a url, i.e. no link, then it uses the second. ... I let you know, how it went. ... ;-)

ThomasSeeker commented 2 years ago

Yes, I am happy! This works:

#!/bin/bash
if [[ $1 == *"https"* ]] || [[ $1 == *"www"* ]]
then
chromium-browser $1
else
chromium-browser $2
fi 
exit

:-)