Multi Commander > Tips and Tricks

SEARCHING with Multi Commander


I've got a question about aliases.
I wanted to create a shortcut "w" for searching in Wikipedia (for example: "w cat" would look up for "cat" i Wikipedia). But I failed miserably.
How a query like this should look like in MC? I've created "test search"  query in Wikipedia and got this:
newbielink: [nonactive]
then I tried to replace "test%20search" part with something else ("?q", "$$1" etc.) but it didn't work.

So my question is: what should I do and how to create other aliases like that (I want to be able to create my own for Polish Wikipedia, Google Images, Wikimedia Commons and other sites).

Thank you in advance for your help,

Mathias (Author):
I don't think you can do that with alias. Because alias replace one command with another. And the parameters that is sent to the alias is sent as parameters to the replaced part. And since it is sent as a parameter there will be an extra space between the url and the parameter and that will not work.

But you can do it using script.

Create a UserDefinedCommand of MultiScript type that looks like this

--- Code: ---@var $url = "";
$url = "" + $arg(0);
MC.Run CMD="{$url}" SHELL
--- End code ---

When you save the script, the script will get a unique ID. (You see that id in the upper right location in the User commands dialog..
lets say it gets the id 77bbd54dec4b412589de6ea89b5d76c2  (You will get a totally different id)

Then in the alias editor you create an alias that calls that script by making "w" be an alias for "@77bbd54dec4b412589de6ea89b5d76c2"
( @ followed by the command id )

Now you can type "w cat" in the command line field

Thank you very much. That worked perfectly... but only with one word searching.
If I type "w john" - that's great. But if I type "w john locke" it only looks up for "john".
How can I change that and make it work for multi-word searching?

Mathias (Author):
you can loop all args and build up the query string. I do not know how wikipedia want to have the url but something like

--- Code: ---@var $query = "";
@var $n = 0;
for( $n = 0; $n < $argcount; $n++ )
   if( $n > 0 )
     // Add delimiter for every search word, depends on the website..
      $query = $query + "+";
   $query = $query + $arg($n);
$url = "" + $query;

--- End code ---

You might have to experiment a bit to get it right.


[0] Message Index

Go to full version