Search via Internet

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