About:
A simple Script AddIn which may be handy from time to time. It allows you to search multiple search engines with either the selected filename, the clipboard or typed text. Double click on a search engine to toggle it on or off.
The script adds a new command to DOpus (Searcher) which you can add to any menu, toolbar or hotkey.
The Search Engines are configurable in the Script AddIn configuration dialog. The format for new engines is: [Google_Images]https://www.google.com/search?tbm=isch&q=%S
. A number of search engines are pre-configured.
The first item between brackets [ ] is the Search Engines name, after that put the url for the search engine, inserting %S where the search terms go.
If a file is selected in the lister when you run this script command it's name_stem will be prefilled in the search box, otherwise the clipboard contents will be pasted in. You can override this by using the CLIP argument which will force Searcher to ignore selected files and just paste from the clipboard. The other available argument is FULLNAME which will force Searcher to use the full name of the first selected item rather than just the name_stem.
The Filename and Clipboard buttons will allow you to toggle between the first selected item in the lister and the clipboard. If nothing is selected in the Lister then the Filename button will be unavailable.
The settings are saved when you close the dialog so Searcher will remember which engines you last used.
History:
- 1.0 (26/4/20)
- Initial Release.
- 1.0.1 (27/4/20)
- Return key now works from the edit control.
- 1.1 (27/4/20)
- Search engines are now configurable.
- 1.2.1 (28/4/20)
- Search engine names can now have spaces in them.
- Added a "Clear" button to clear the search string.
- Added more default search engines.
- Added new command argument: FULLNAME which will force Searcher to use the full name of the first selected item instead of just the name_stem.
Installation:
- Download: Searcher 1.2.1.js.txt (9.3 KB)
- Drag the .js.txt file to Preferences / Toolbars / Scripts
Usage:
- Download: Searcher.dcf (240 Bytes)
- Select "Settings/Customize Toolbar..." from your Lister and then drag the .dcf file to any toolbar you like.
Script:
The script is included for reference only. To use searcher just download the script and button above.
// Searcher
// (c) 2020 Steve Banham
scriptName = "Searcher";
scriptVersion = "1.2.1";
scriptDate = "28/4/2020";
scriptCopyright = "(c) 2020 Steve Banham";
scriptMinVersion = "12.20";
scriptDesc = "Find selected filename, or clipboard content in various search engines.";
function OnInit(initData) {
initData.name = scriptName;
initData.version = scriptVersion;
initData.copyright = scriptCopyright;
initData.desc = scriptDesc;
initData.default_enable = true;
initData.min_version = scriptMinVersion;
var vecSearchEngines = DOpus.NewVector();
vecSearchEngines.push_back = "[Google]https://www.google.com/search?q=%S";
vecSearchEngines.push_back = "[Google Images]https://www.google.com/search?tbm=isch&q=%S";
vecSearchEngines.push_back = "[Bing]https://www.bing.com/search?q=%S";
vecSearchEngines.push_back = "[Bing Images]https://www.bing.com/images/search?q=%S";
vecSearchEngines.push_back = "[DuckDuckGo]https://duckduckgo.com/?q=%S";
vecSearchEngines.push_back = "[DuckDuckGo Images]https://duckduckgo.com/?q=%S&ia=images&iax=images";
vecSearchEngines.push_back = "[Wikipedia]https://en.wikipedia.org/wiki/%S";
vecSearchEngines.push_back = "[Opus Resource Centre]https://resource.dopus.com/search?q=%S";
vecSearchEngines.push_back = "[YouTube]https://www.youtube.com/results?search_query=%S";
vecSearchEngines.push_back = "[Amazon]https://www.amazon.com/s?k=%S";
vecSearchEngines.push_back = "[Amazon Australia]https://www.amazon.com.au/s?k=%S";
vecSearchEngines.push_back = "[Ebay]https://www.ebay.com/sch/i.html?_nkw=%S";
vecSearchEngines.push_back = "[Ebay Australia]https://www.ebay.com.au/sch/i.html?_nkw=%S";
initData.config.search_engines = vecSearchEngines;
initData.config_desc = DOpus.Create.Map("search_engines", "List of search engines available to select.");
var cmd = initData.AddCommand();
cmd.name = "Searcher";
cmd.method = "onSearcher";
cmd.desc = "Find selected filename, or clipboard content in various search engines.";
cmd.label = "Searcher";
cmd.template = "CLIP/S,FULLNAME/S";
}
function onSearcher(scriptCmdData) {
var srcTab = scriptCmdData.func.sourcetab;
var strEngineName;
var strEngineUrl;
var dlg = DOpus.Dlg;
dlg.title = scriptName + " " + scriptVersion+ " - Directory Opus";
dlg.template = "dlgSearch";
dlg.LoadPosition("Steve_Searcher");
dlg.detach = true;
dlg.Create();
dlg.Control("listEngines").columns.AddColumn("Search Engine");
dlg.Control("listEngines").columns.AddColumn("Active");
for (var eEngines = new Enumerator(Script.Config["search_engines"]); !eEngines.atEnd(); eEngines.moveNext()) {
strEngineName = eEngines.item();
if (strEngineName.search("]") > -1) {
strEngineName = strEngineName.substring(1,strEngineName.search("]"));
strEngineNameSafe = strEngineName.replace(/ /g, "_");
dlg.Control("listEngines").AddItem(strEngineName);
if (!DOpus.Vars.Exists("Searcher_" + strEngineNameSafe) || DOpus.Vars.Get("Searcher_" + strEngineNameSafe) == undefined) {
DOpus.Vars.Set("Searcher_" + strEngineNameSafe) = "Yes";
dlg.Control("listEngines").GetItemByName(strEngineName).subitems(0) = "Yes";
}
else {
dlg.Control("listEngines").GetItemByName(strEngineName).subitems(0) = DOpus.Vars.Get("Searcher_" + strEngineNameSafe);
}
DOpus.Vars("Searcher_" + strEngineNameSafe).persist = true;
}
else {
DOpus.Output("Error in search_engines configuration.");
return;
}
}
if (scriptCmdData.func.args.got_arg.clip) {
dlg.Control("editSearch").value = DOpus.GetClip();
}
else {
if (srcTab.stats.selitems > 0) {
if (scriptCmdData.func.args.got_arg.fullname) {
dlg.Control("editSearch").value = srcTab.selected(0).name;
}
else {
dlg.Control("editSearch").value = srcTab.selected(0).name_stem;
}
}
else {
dlg.Control("editSearch").value = DOpus.GetClip();
}
}
if (srcTab.stats.selitems < 1) {
dlg.Control("btnFile").enabled = false;
}
dlg.Control("listEngines").columns.AutoSize();
dlg.Show();
while (true) {
var msg = dlg.GetMsg();
if (!msg.result) break;
if (msg.event == "click" && dlg.Control("btnFile").focus == true) {
if (srcTab.stats.selitems > 0) {
if (scriptCmdData.func.args.got_arg.fullname) {
dlg.Control("editSearch").value = srcTab.selected(0).name;
}
else {
dlg.Control("editSearch").value = srcTab.selected(0).name_stem;
}
}
}
if (msg.event == "click" && dlg.Control("btnClip").focus == true) {
if (DOpus.GetClipFormat() == "text") {
dlg.Control("editSearch").value = DOpus.GetClip();
}
}
if (msg.event == "click" && dlg.Control("btnClear").focus == true) {
dlg.Control("editSearch").value = "";
}
if (msg.event == "dblclk" && dlg.Control("listEngines").focus == true) {
var intSelItem = dlg.Control("listEngines").value.index;
var strEngineNameSafe = dlg.Control("listEngines").GetItemAt(intSelItem).name;
strEngineNameSafe = strEngineNameSafe.replace(/ /g, "_");
if(dlg.Control("listEngines").GetItemAt(intSelItem).subitems(0) == "Yes") {
DOpus.Vars.Set("Searcher_" + strEngineNameSafe) = "No";
dlg.Control("listEngines").GetItemAt(intSelItem).subitems(0) = "No";
}
else {
DOpus.Vars.Set("Searcher_" + strEngineNameSafe) = "Yes";
dlg.Control("listEngines").GetItemAt(intSelItem).subitems(0) = "Yes";
}
}
if (msg.event == "click" && dlg.Control("btnSearch").focus == true || msg.event == "click" && dlg.Control("editSearch").focus == true) {
var intSearch = 0;
if (dlg.Control("editSearch").value == "") {
DOpus.Output("No text to search.");
}
else {
for (var eEngines = new Enumerator(Script.Config["search_engines"]); !eEngines.atEnd(); eEngines.moveNext()) {
var cmd = scriptCmdData.func.command;
strEngineUrl = eEngines.item();
strEngineName = eEngines.item();
strEngineName = strEngineName.substring(1,strEngineName.search("]"));
strEngineNameSafe = strEngineName.replace(/ /g, "_");
if (dlg.Control("listEngines").GetItemByName(strEngineName).subitems(0) == "Yes") {
intSearch = 1;
var strSearch = dlg.Control("editSearch").value;
strSearch = strSearch.replace(/ /g, "+");
strEngineUrl = strEngineUrl.substring(strEngineUrl.search("]"));
strEngineUrl = strEngineUrl.replace("]","");
strEngineUrl = strEngineUrl.replace("%S", strSearch);
if (strEngineNameSafe == "Wikipedia") {
strEngineUrl = strEngineUrl.replace(/\+/g, "_");
}
cmd.AddLine(strEngineUrl);
}
}
if (intSearch == 1) {
cmd.Run();
cmd.Clear();
}
else DOpus.Output("No Search Engines Selected.");
}
}
}
dlg.SavePosition("Steve_Searcher");
}
function OnAboutScript(aboutData){
dlg = DOpus.Dlg;
dlg.window = aboutData.window;
dlg.title = scriptName + scriptVersion + " - Directory Opus";
dlg.message = scriptName + " v" + scriptVersion + "\t\t\t\t\t" + scriptDate + "\n\n" + scriptDesc + "\n\n" + scriptCopyright;
dlg.buttons = "Close";
dlg.icon = "info";
dlg.show;
}
==SCRIPT RESOURCES
<resources>
<resource name="dlgSearch" type="dialog">
<dialog fontsize="8" height="202" lang="english" resize="yes" title="Searcher - Directory Opus" width="165">
<control halign="left" height="12" name="editSearch" resize="w" type="edit" width="157" x="4" y="4" />
<control height="14" name="btnFile" title="&Filename" type="button" width="50" x="4" y="20" />
<control height="14" name="btnClip" title="&Clipboard" type="button" width="50" x="57" y="20" />
<control fullrow="yes" height="142" name="listEngines" noheader="yes" nosortheader="yes" resize="wh" type="listview" viewmode="details" width="157" x="4" y="38" />
<control default="yes" height="14" name="btnSearch" resize="xy" title="&Search..." type="button" width="50" x="57" y="184" />
<control close="0" height="14" name="btnClose" resize="xy" title="C&lose" type="button" width="50" x="110" y="184" />
<control height="14" name="btnClear" title="Cl&ear" type="button" width="50" x="110" y="20" />
</dialog>
</resource>
</resources>