// RunWindow // (c) 2017 Leo Davidson // This is a script for Directory Opus. // See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. // Called by Directory Opus to initialize the script function OnInit(initData) { initData.name = "RunWindow"; initData.version = "1.0"; initData.copyright = "(c) 2017 Leo Davidson"; initData.url = "https://resource.dopus.com/t/runwindow-send-commands-to-a-specific-window/25289"; initData.desc = "Run command for a given window"; initData.default_enable = true; initData.min_version = "12.0"; var cmd = initData.AddCommand(); cmd.name = "RunWindow"; cmd.method = "OnRunWindow"; cmd.desc = "Run command for a given window"; cmd.label = "RunWindow"; cmd.template = "HWND/K,TITLE/K,LAYOUT/K,ALWAYSRUN/S,CMD/R"; cmd.hide = false; cmd.icon = "window"; } // Implement the RunWindow command function OnRunWindow(scriptCmdData) { var args = scriptCmdData.func.args; var hwnd = args.hwnd; var title = args.title; var layout = args.layout; var alwaysrun = args.alwaysrun; var cmdstr = args.cmd; if (cmdstr === undefined) { return; } if (title !== undefined) { title = DOpus.FSUtil.NewWild(title,"d"); // "d" means just simple MS-DOS wildcards. } if (layout !== undefined) { layout = DOpus.FSUtil.NewWild(layout,"d"); // "d" means just simple MS-DOS wildcards. } var listers = DOpus.listers; var listerMatch = undefined; // Give priority to the last active lister, if any. if (checkLister(listers.lastactive, hwnd, title, layout)) { listerMatch = listers.lastactive; } else { for(var eListers = new Enumerator(listers); !eListers.atEnd(); eListers.moveNext()) { var lister = eListers.item(); if (checkLister(lister, hwnd, title, layout)) { listerMatch = lister; break; } } } var cmd = DOpus.Create.Command; if (listerMatch !== undefined && listerMatch !== 0) { cmd.SetSourceTab(listerMatch.activetab); } else if (!alwaysrun) { return; } cmd.RunCommand(cmdstr); } function checkLister(lister, hwnd, title, layout) { if (lister === undefined || lister === 0 || (hwnd !== undefined && hwnd != lister) || (title !== undefined && !title.Match(lister.title)) || (layout !== undefined && !layout.Match(lister.layout))) { return false; } return true; }