Search via Internet

I have a button searching selected file/folder in Google:

"http://www.google.com/search?q={o}"

How to avoid unextracting when selecting a file/folder from an archive (DO just should search for the name, so no extraction should be necessary)? And how to exclude the extension?

Thanks in advance.

@nolocalizefiles prevents the file being downloaded from FTP.

You may need to URL encode the filename, which is best done using scripting. JScript and VBScript have URL encoding functions built in, if I remember correctly, but it's been a while.

Use this to avoid extraction and exclude the extension:

@nolocalizefiles
"http://www.google.com/search?q={o|noext}"

Thanks.

After using above code (see Kundal) some time I found out that it cuts everything after a "&" in filenames.

Which syntax is needed to simply search for a filename incl. all kind of chars (but of course excluding extension)?

You'd need a script to modify the file name to use the appropriate encoding for a Google URL.

e.g. replace & with %26

JScript has a function for URL-encoding things which may do everything, but it might depend on what Google expects.

This seems to work fine with google.com:

Google Search (JScript script function button)

function OnClick(data) {
  data.func.command.ClearFiles();
  var objEnum = new Enumerator(data.func.sourcetab.selected);
  while (!objEnum.atEnd()) {
	var item = objEnum.item().name_stem; objEnum.moveNext();
	var replacePlus = item.replace(/\+/g,"%%2B")
	var replaceSpace = replacePlus.replace(/ /g,"+")
	var search = replaceSpace.replace(/&/g,"%%26");
	data.func.command.RunCommand("http://www.google.com/search?q=" + search);
  }
}
2 Likes

Modifying Kundal's script slightly, JScript's encodeURIComponent covers a few more cases ( , / ? : @ & = + $ # although not all are possible in filenames to start with of course).

(The "replace" line is because it needs to double the % characters before running the command.)

function OnClick(data) {
  data.func.command.ClearFiles();
  var objEnum = new Enumerator(data.func.sourcetab.selected);
  while (!objEnum.atEnd()) {
   var item = objEnum.item().name_stem; objEnum.moveNext();
   var encoded = encodeURIComponent(item);
   var search = encoded.replace(/%/g,"%%");
   data.func.command.RunCommand("http://www.google.com/search?q=" + search);
  }
}
3 Likes

Nice, I tried encodeURI which didn't work.

That a what I was thinking of as well. I stumbled on the other one while searching for the first one's exact name, which was lucky. :slight_smile:

I never would be able to script such things, so thank you both!

I used this with Docuwiki so now I can search anything in my documentary videos with one click. Thanks a ton guys!

I added it to the context menu but these pop up:
image

Set the button to Script mode, and then JScript as the language.

How do I set JScript as the language?

I don't see the same things

Ah, if it's in a context menu item, add a new line at the top, above the function OnClick... line with this:

@script jscript

Splendid. thanks

You can do this more easily, and without scripting, in the new beta: Directory Opus 12.23.2 (Beta)

https://www.google.com/search?q={file|urlencode}
1 Like