//todo: //- remove Delay() after SetClip() once GPSoft fixes the issue //- PASTETOFOLDERS and PASTETOCONTAINERS and using the MOVE switch probably does // not work as expected for multiple folders/containers!!! //v0.3.7 - 2016.09.21 //- new option FOLDERS to specify the target folders to paste into via commandline //v0.3.6 - 2016.04.28 //- CLEAR/O -> CLEAR/S //v0.3.5 - 2016.04.28 //- new feature "PASTETOCONTAINERS" to copy/move clipboard items to the parent folder of items. // this is handy for moving items around in flatview without folders by "pasting" // onto files, which already reside in the desired target (as shown in location column) //- new switch "MOVE" to move instead of copy for PASTEFROMCLIP, PASTETOFOLDERS and PASTETOCONTAINERS //v0.3.1 - 2016/03 //- more efficient and robust TRIM (fixed delay removed, testing for correctly set clip-data) //- new CLEAR argument to clear the clipboard //v0.3 - 2016/03 //- new feature "TRIM" to trim clipboard content //- internal enhancements //v0.2 - 2015/07 //- new feature "PASTEEMPTY" to create empty files from clipboard content //- output handled by XLog /////////////////////////////////////////////////////////////////////////////// var TEMPLATE = "" + "COPYNAMES/O,PASTEFROMCLIP/S,PASTETOFOLDERS/S,FOLDERS/O,PASTETOCONTAINERS/S,MOVE/S,PASTEEMPTY/S,"+ "TRIM/O[,left,right],TRIMCHARS/K,"+ "CLEAR/S,"+ //generic "NODESELECT/S,NOFAIL/S,XLOG/O[off,xception,error,warning,info,,trace,dump,all]"; /////////////////////////////////////////////////////////////////////////////// function OnInit(data){ //uid added via script wizard (do not change after publishing this script) var uid = "FC9C51A8-90DA-4B85-B93B-5EA5097A942F"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=23797"; data.name = "Command.Generic: ClipboardEx"; data.log_prefix = "ClipEx"; data.desc = "An extension to the internal clipboard command."; data.copyright = "tbone"; data.version = "0.3.7"; data.default_enable = true; /////////////////////////////////////////////////////////////////////////// function ConfigHelper(data){ //v1.2 var t=this; t.d=data; t.c=data.config; t.cd=DOpus.Create.Map(); t.add=function(name, val, des){ t.l={n:name,ln:name. toLowerCase()}; return t.val(val).des(des);} t.des=function(des){ if (!des) return t; if (t.cd.empty) t.d.config_desc=t.cd; t.cd(t.l.n)=des; return t;} t.val=function(val){ var l=t.l; if (l.v!==l.x&&typeof l.v=="object") l.v.push_back(val);else l.v=t.c[l.n]=val;return t;} t.trn=function(){return t.des(t("script.config."+t.l.ln));}} /////////////////////////////////////////////////////////////////////////// var cfg = new ConfigHelper(data); cfg.add('XLog', DOpus.Create.Vector()). val(5). //first value is the default index for dropdown selections like this val("Off").val("Xception").val("Error").val("Warning").val("Info").val("Normal").val("Trace").val("Dump").val("All"). des('Console output level. The higher, the more output will be visible in the console window. '); var cmd = data.AddCommand(); cmd.name = "ClipboardEx"; cmd.method = "Command_ClipboardEx"; cmd.desc = data.desc; cmd.label = "ClipboardEx"; cmd.template = TEMPLATE; } /////////////////////////////////////////////////////////////////////////////// var COMMAND_FAILURE = true; var COMMAND_USERABORT = true; var COMMAND_BADPARAMS = true; var COMMAND_SUCCESS = false; var NetMagic = new NetMagic(); var FSMagic = new FSMagic(); var TextMagic = new TextMagic(); /////////////////////////////////////////////////////////////////////////////// String.prototype.lTrim = function(chr){chr=chr||"\\s";return new String(this.replace(new RegExp("^"+chr+"*"),''));} String.prototype.rTrim = function(chr){chr=chr||"\\s";return new String(this.replace(new RegExp(chr+"*$"),''));} String.prototype.trim = function(chr){return this.lTrim(chr).rTrim(chr);} String.prototype.left = function(chrs){return this.substring(0,chrs);} String.prototype.right = function(chrs){return this.substring(this.length-chrs);} /////////////////////////////////////////////////////////////////////////////// function Command_ClipboardEx(data) { var args = ArgsMagic(data, null, TEMPLATE), result = null; if (args["XLOG"].exists){ XLog = args["XLOG"].value; } Log("CmdLine: " + data.cmdline,"D"); if (args["NODESELECT"].exists) data.func.command.deselect = false; if (args["NOFAIL"].exists) COMMAND_FAILURE = COMMAND_SUCCESS; if (0); else if (args["COPYNAMES"].exists) return ClipboardEx_COPYNAMES(data.func.command, data.func.sourcetab, args); else if (args["PASTEFROMCLIP"].exists) return ClipboardEx_PASTEFROMCLIP(data.func.command, data.func.sourcetab, args); else if (args["PASTETOFOLDERS"].exists) return ClipboardEx_PASTETOFOLDERS(data.func.command, data.func.sourcetab, args); else if (args["PASTETOCONTAINERS"].exists) return ClipboardEx_PASTETOCONTAINERS(data.func.command, data.func.sourcetab, args); else if (args["PASTEEMPTY"].exists) return ClipboardEx_PASTEEMPTY(data.func.command, args); else if (args["TRIM"].exists) return ClipboardEx_TRIM(data.func.command, data.func.sourcetab, args); else if (args["CLEAR"].exists) return ClipboardEx_CLEAR(data.func.command); if (result===null){ Log("Bad/incomplete params.","X"); return COMMAND_BADPARAMS; } return result; } /////////////////////////////////////////////////////////////////////////////// function ClipboardEx_CLEAR(cmd, sourcetab, args){ Log("ClipboardEx_CLEAR():", "T", 1); cmd.deselect = false; cmd.ClearFiles(); var result, i = 1; while (1){ //due to possible timing or concurrent access issues try{ result = DOpus.SetClip(); break; } catch (e){} if (i++>50){ Log("Clearing clipboard failed after "+i+" attempts.", "x"); Log("-", "T", -1); return COMMAND_FAILURE; } DOpus.Delay(10); } Log("-", "T", -1); return COMMAND_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// function ClipboardEx_TRIM(cmd, args){ Log("ClipboardEx_TRIM():", "T", 1); cmd.deselect = false; cmd.ClearFiles(); var clipTextOrig = ""+DOpus.GetClip("text"), clipText = ""; if (!clipTextOrig){ Log("No usable clipboard content, aborting.", "X"); return COMMAND_FAILURE; //no valid clipboard content } clipText = clipTextOrig var chars = args["TRIMCHARS"].value || " "; Log("Mode : " + args["TRIM"].value, "d"); Log("Chars: [" + chars + "]", "d"); Log("Text (b): [" + clipText.substring(0,30) + "] (might be truncated)", "d"); switch(args["TRIM"].value){ case "both": clipText = clipText.trim(chars); break; case "right": clipText = clipText.rTrim(chars); break; case "left": clipText = clipText.lTrim(chars); break; } Log("Text (a): [" + clipText.substring(0,30) + "] (might be truncated)", "d"); //clipText not changed, skipping expensive SetClip() if (clipTextOrig==clipText){ Log("Setting clipboard skipped, data not changed.", "d"); Log("-", "T", -1); return COMMAND_SUCCESS; } DOpus.SetClip(clipText); var i = 1; while (1){ //due to possible timing or concurrent access issues if (DOpus.GetClip("text") != ""){ if (i>1) Log("Setting clipboard succeeded in attempt #"+i, "i"); break; } if (i++>50){ Log("Setting clipboard failed after "+i+" attempts.", "x"); Log("-", "T", -1); return COMMAND_FAILURE; } DOpus.Delay(10); } Log("-", "T", -1); return COMMAND_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// function ClipboardEx_PASTEEMPTY(cmd, sourcetab, args){ Log("ClipboardEx_PASTEEMPTY():", "T", 1); cmd.deselect = false; cmd.ClearFiles(); //get clean and secure array of filepaths from clipboard var items = TextMagic.TextToFilePaths( DOpus.GetClip("text") ); if (!items.length){ Log("No usable clipboard content, aborting.", "X"); return COMMAND_FAILURE; //no valid clipboard content } for(var c=0;c '' and ipenabled = true" ); var enumItems = new Enumerator(colItems); var addresses = []; for (;!enumItems.atEnd(); enumItems.moveNext()) addresses.push(enumItems.item().IPAddress.toArray()[0]); if (!addresses.length) return ""; this.localIPAddress = addresses[0]; return this.localIPAddress; } } /////////////////////////////////////////////////////////////////////////////// function FSMagic(){ this.version = 0.4; this.fso = new ActiveXObject("Scripting.FileSystemObject"); this.mappingsCached = []; /////////////////////////////////////////////////////////////////////////// this.GetTmpFileName = function(prefix, extension) { var tFolder = this.fso.GetSpecialFolder(2); //2 = temp folder var tFile = this.fso.GetTempName(); if (prefix!=undefined) tFile=prefix+tFile; if (extension!=undefined) tFile+=extension; return { path : tFolder.Path, name : tFile, fullname: tFolder.Path+'\\'+tFile }; } /////////////////////////////////////////////////////////////////////////// this.OpenFile = function(filePath, mode, encoding){ mode = mode || "r"; encoding = encoding || "unicode"; var testEncoding = (encoding=="try"?true:false); var encodings = {ascii:0,unicode:-1,def:-2}, modes = {r:1,w:2,a:8}; try{ if (mode=="w" && this.fso.FileExists(filePath)) this.fso.DeleteFile(filePath); if (mode=="r" && testEncoding) encoding="ascii"; var file = this.fso.OpenTextFile(filePath, modes[mode], true, encodings[encoding]); if (testEncoding && mode!="w" && !file.AtEndOfStream){ var line = file.ReadLine(); if (line.indexOf("")==0) {//utf8 bom Log("Unsupported UTF8 file detected, convert to UTF16-LE or UNICODE first (with notepad maybe).", "X"); file.Close(); return null; } if (line.indexOf("þÿ")==0) {//utf16 be bom Log("Unsupported UTF16-BE file detected, convert to UTF16-LE or UNICODE first (with notepad maybe).", "X"); file.Close(); return null; } if (line.indexOf("ÿþ") == 0) encoding="unicode"; //utf16 le bom file.Close(); //close and reopen file, since we cannot rewind the textstream in case //it is ascii and for unicode we need to reopen it anyway var file = this.fso.OpenTextFile(filePath, modes[mode], true, encodings[encoding]); } return file; } catch(e){ Log("Error opening file ["+filePath+"]: " + e, "D"); return null; } } /////////////////////////////////////////////////////////////////////////// this.CreatePath = function(fullPath){ //version = 0.5.1; fullPath = new String(fullPath); if (this.fso.FolderExists(fullPath)) return true; var drive = fullPath.substring(0,3); var dirs = fullPath.split("\\"); var path = "" for(var i=1;i"); if (parts.length>1) opValue = parts.slice(1).join(""); this.options[opName] = opValue; } if (!(!this.value && subOpsTemplate)) return; if (!(match = subOpsTemplate.match(/\<(.+?)\>/))) return; this.options[match[1]] = true; this.value = match[1]; } /////////////////////////////////////////////////////////////////////////// var types = {s:"switch",k:"keyword",o:"optional",n:"numeric",m:"multiple",r:"raw"}; var names = template.replace(/\/(.)\,/g,"/$1;").replace(/\]\,/g,"];").split(";"), args = []; for(arg in names) { var parts = names[arg].split("/"); var name=parts[0].toUpperCase(), subOpsTemplate=null; var parts2 = parts[1].split("["); var type=parts2[0].toLowerCase(); if (parts2.length>1) subOpsTemplate = parts2[1].substring(0,parts2[1].length-1); var exists=(data&&data.func.args.got_arg[name])||(jsonData&&(jsonData[name]!=undefined))||false; var value = (data && data.func.args[name]) || (jsonData && jsonData[name]) || undefined; args.push( args[name] = new Arg(name, types[type], exists, value, subOpsTemplate )); } /////////////////////////////////////////////////////////////////////////// args.Get = function( argName, configName, noneValue){ var arg = this[argName = argName.toUpperCase()]; if (!arg) throw new Error(0, "Unknown parameter ["+argName+"]"); if (arg.exists) return arg.value; if (!configName) return noneValue; if (typeof Script.config[configName] == "string") return new String(""+Script.config[configName]); return Script.config[configName]; } return args; } /////////////////////////////////////////////////////////////////////////////// function Log(text, lvl, ind){ //XLog v0.41 var u,lvs={o:0,x:1,e:2,w:3,i:4,n:5,t:6,d:7,a:8},i=["","X","E","W","I","","","",""]; if (typeof XLog==(u="undefined")){var v=DOpus.Vars; if (v.Exists("XLog") && typeof XLogForce==u) {XLog=v.Get("XLog"); }} if (typeof XLog==u){var c=Script.Config; if(typeof c!="undefined" && typeof c.XLog!=u){ XLog=c.XLog; }} if (typeof XLog==u){XLog="normal";} if(XLog.paused===undefined){ if(XLog===true) var L=5; else if(!isNaN(parseInt(XLog,10))) var L=XLog*1; else var L=lvs[(""+XLog).substring(0,1)]; XLog={paused:false,I:0,L:L};} lvl=(lvl==undefined?5:lvs[lvl.substring(0,1).toLowerCase()]); if (!(lvl && XLog.L && !XLog.paused && (lvl<=XLog.L))){ return;} var pad = (XLog.I==0?"":new Array(XLog.I+1).join(" ")); if (i[lvl])pad = i[lvl]+(!pad?" ":pad.substring(1)); if (text!="-"){ var d=DOpus; if (d.Version.AtLeast("11.13.1")) d.Output(pad+text,((lvl==1||lvl==2)?1:0)); else d.Output(pad+text);} ind=(ind!==undefined?ind:0);XLog.I+=ind;if(XLog.I<0)throw new Error("XLog indent went sub-zero."); } /////////////////////////////////////////////////////////////////////////////// function OnAboutScript(data){ //v0.1 var cmd = DOpus.Create.Command(); if (!cmd.Commandlist('s').exists("ScriptWizard")){ if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+ "Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+ "easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window)) cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');} else cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"'); } //MD5 = "c1d7c3321545f869c9f905eadf1d178d"; DATE = "2016.09.22 - 00:10:34"