// Area Command // (C) 2015 Leo Davidson // // This is a script for Directory Opus. // See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. numAreas = 10; function OnInit(initData) { initData.name = "Area Command"; initData.desc = "Run different commands when the mouse is in different areas."; initData.copyright = "(C) 2015 Leo Davidson"; initData.version = "1.0"; initData.default_enable = true; initData.min_version = "11.15.3" var cmd = initData.AddCommand(); cmd.name = "AreaCommand"; cmd.method = "OnAreaCommand"; cmd.desc = "Run different commands when the mouse is in different areas."; cmd.label = "AreaCommand"; cmd.template = ""; monitors = DOpus.Create.SysInfo.Monitors; descs = DOpus.NewMap(); for (i = 0; i < numAreas; ++i) { initData.config[ "Area_" + i ] = GetMonitorRect(monitors,i); initData.config[ "Area_" + i + "_Command" ] = "Go NEW"; descs( "Area_" + i ) = "Screen area (left top width height) the mouse has to be in." descs( "Area_" + i + "_Command" ) = "Command to run when the mouse is in the corresponding area." } initData.config._descriptions = descs; } function GetMonitorRect(monitors, idx) { if (idx >= monitors.count) return ""; r = monitors(idx); return r.left + " " + r.top + " " + r.width + " " + r.height; } function IsInRect(strRect, x, y) { coords = strRect.split(" "); if (coords.length < 4) return false; l = parseInt(coords[0]); t = parseInt(coords[1]); r = parseInt(coords[2]) + l; b = parseInt(coords[3]) + t; return (x >= l && x < r && y >= t && y < b); } function TrimString(s) { return s.replace(new RegExp("^ *(.*?) *$"),"$1"); } function OnAreaCommand(scriptCmdData) { sysInfo = DOpus.Create.SysInfo; x = sysInfo.MousePosX; y = sysInfo.MousePosY; cfg = Script.config; for (i = 0; i < numAreas; ++i) { if (IsInRect(cfg[ "Area_" + i ], x, y)) { cmdLine = TrimString(cfg[ "Area_" + i + "_Command" ]); if (cmdLine != "") { scriptCmdData.func.command.RunCommand(cmdLine); break; } } } }