function OnInit(initData) { initData.name = 'ClipCopy'; initData.version = '2024-04-13'; initData.url = 'https://resource.dopus.com/t/clipcopy-copy-stuff-to-the-clipboard/44626'; initData.desc = 'Copy various information to the clipboard'; initData.default_enable = true; initData.min_version = '12.0'; } function OnAddCommands(addCmdData) { var cmd = addCmdData.AddCommand(); cmd.name = 'ClipCopy'; cmd.method = 'OnClipCopy'; cmd.template = '' + 'button/s,' + 'columns/s,' + 'description/s,' + 'fileasbitmap/s,' + 'nameandcloudlink/s,' + 'nameanddescription/s,' + 'nameandprodversion/s,' + 'nameandsize/s,' + 'nameandsizeauto/s,' + 'nameandtarget/s,' + 'noheading/s,' + 'nolog/s,' + 'osmlink/s,' + 'quickfilter/s,' + 'target/s,' + 'targetpath/s,' + 'values/k,' + 'wanip/s'; cmd.hide = false; cmd.icon = 'script'; } function OnClipCopy(scriptCmdData) { var cmd = scriptCmdData.func.command; var tab = scriptCmdData.func.sourcetab; var args = scriptCmdData.func.args; var argsmap = scriptCmdData.func.argsmap; cmd.deselect = false; var tmp = ''; if (false); else if (args.columns) CopyColumns(); else if (args.description) CopyDescription(); else if (args.fileasbitmap) CopyFileAsBitmap(); else if (args.nameandcloudlink) CopyNameAndCloudlink(); else if (args.nameanddescription) CopyNameAndDescription(); else if (args.nameandprodversion) CopyNameAndProdversion(); else if (args.nameandsize) CopyNameAndSize(); else if (args.nameandsizeauto) CopyNameAndSizeAuto(); else if (args.nameandtarget) CopyNameAndTarget(); else if (args.osmlink) CopyOsmLink(); else if (args.quickfilter) CopyQuickFilter(); else if (args.target) CopyTarget(); else if (args.targetpath) CopyTargetPath(); else if (args.values) CopyValues(); else if (args.wanip) CopyWanIp(); if (tmp) { DOpus.SetClip(tmp); } else { tmp = '<<< Clipboard has not been changed >>>'; } Log(tmp); // ==== function CopyColumns() { var colNames = ''; for (var e = new Enumerator(tab.format.columns); !e.atEnd(); e.moveNext()) { var colName = e.item().name; if (colNames) colNames += ', '; colNames += colName; if (colName == 'name') continue; if (tmp) tmp += '\r\n'; tmp += 'Set COLUMNSTOGGLE="' + colName + '(!,a,0)"'; } tmp += '\r\n'; tmp += '\r\n'; for (var e = new Enumerator(tab.format.columns); !e.atEnd(); e.moveNext()) { if (tmp) tmp += '\r\n'; tmp += 'Set COLUMNSADD="' + e.item().name + '(!,' + e.item().width + ',' + e.item().max + ')"'; } if (args.button) { var arr = tmp.split('\r\n'); tmp = ''; tmp += '' + '\r\n'; tmp += '' + '\r\n'; } } function CopyDescription() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.metadata.other.autodesc; } } function CopyFileAsBitmap() { if (!tab.selected.count) return; var item = tab.selected(0); cmd.RunCommand('Show FILE="' + item + '" USEEXISTING=no'); var newVwrs = cmd.results.newviewers; newVwrs(0).Command('selectall'); newVwrs(0).Command('copy'); newVwrs(0).Command('close'); } function CopyNameAndCloudlink() { DOpus.Output('Enumerating...'); DOpus.Output(''); for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); DOpus.Output(item); tmp += item.name + '\r\n'; var linkFound = false; GetCloudLink('VERB="{3340B3D7-438C-4FC9-81BF-8D9D81B05730}"'); // Dropbox GetCloudLink('VERB="{5250E46F-BB09-D602-5891-F476DC89B702}"'); // OneDrive GetCloudLink('VERB="GetMEGALink"'); // Mega // Pick the language that fits your system Google Drive GetCloudLink('LABEL="Copy link to clipboard"'); // GetCloudLink('LABEL="Copia link negli appunti"'); // GetCloudLink('LABEL="Copiar enlace en el portapapeles"'); // GetCloudLink('LABEL="Copier le lien dans le presse-papiers"'); // GetCloudLink('LABEL="Link in die Zwischenablage kopieren"'); if (!linkFound) tmp += 'No cloud link found\r\n'; tmp += '\r\n'; } DOpus.Output(''); DOpus.Output('... done!'); DOpus.Output(''); function GetCloudLink(menuCommand) { DOpus.SetClip(); cmd.RunCommand('ContextMenu' + ' ITEMMODE' + ' FILE="' + item + '"' + ' ' + menuCommand); for (var i = 0; i < 20; i++) { DOpus.Delay(100); var clipText = DOpus.GetClip(); if (!clipText) continue; tmp += clipText + '\r\n'; linkFound = true; break; } DOpus.Output((clipText ? clipText : '*** none') + ' (Number of wait loops: ' + i + ')'); } } function CopyNameAndDescription() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.name + '\t' + item.metadata.other.autodesc; } } function CopyNameAndProdversion() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.name + '\t' + item.metadata.exe.prodversion; } } function CopyNameAndSize() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (tmp) tmp += '\r\n'; tmp += item.name + '\t' + item.size; } } function CopyNameAndSizeAuto() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (tmp) tmp += '\r\n'; tmp += item.name + '\t' + item.size.fmt; } } function CopyNameAndTarget() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.name + '\t' + item.metadata.other.target; } } function CopyOsmLink() { var zoomlevel = 18; for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; var lat = item.metadata.image.latitude; if (typeof lat != 'number') continue; var lon = item.metadata.image.longitude; if (typeof lon != 'number') continue; if (tmp) tmp += '\r\n'; tmp += 'https://www.openstreetmap.org/?' + '&mlat=' + lat + '&mlon=' + lon + '#map=' + zoomlevel + '/' + lat + '/' + lon; } } function CopyQuickFilter() { var evalMode = cmd.IsSet('Set QUICKFILTERFLAGS=evalon'); var reMode = cmd.IsSet('Set QUICKFILTERFLAGS=regexpon'); var quickFilter = tab.quickfilter.filter; var cmdLine = 'Set' + ' QUICKFILTERFLAGS=eval' + (evalMode ? 'on' : 'off') + ',regexp' + (reMode ? 'on' : 'off') + ' QUICKFILTER="' + quickFilter.replace(/"/g, '""') + '"'; if (args.button) { tmp += '' + '\r\n'; tmp += '' + '\r\n'; } else { tmp = cmdLine; } } function CopyTarget() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.metadata.other.target; } } function CopyTargetPath() { for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) { var item = e.item(); if (item.metadata == 'none') continue; if (tmp) tmp += '\r\n'; tmp += item.metadata.other.target.pathpart; } } function CopyWanIp() { var xhr = new ActiveXObject('MSXML2.XMLHTTP'); var urlIpCheck = 'https://checkip.amazonaws.com'; xhr.open('GET', urlIpCheck, false); xhr.send(); tmp = xhr.status == 200 ? xhr.responseText.replace(/[^.0-9]/g, '') : 'HTTP STATUS: ' + xhr.status; } function CopyValues() { if (!DOpus.version.AtLeast('13')) { DOpus.Output('Sorry, ClipCopy VALUES requires Opus 13.'); return; } DOpus.vars.Set('columnValue', ''); var argValues = args.values; argValues = argValues.replace(/,+/g, ','); argValues = argValues.replace(/^,|,$/g, ''); if (!argValues) argValues = 'name'; var arr = argValues.split(','); var cmdLine = ''; for (var i = 0; i < arr.length; i++) { if (cmdLine) cmdLine += '+"\t"+'; cmdLine += 'Val("' + arr[i] + '")'; } cmdLine = 'Select' + ' FILTERDEF' + ' =$glob:columnValue+=' + cmdLine + '+"\r\n"' + ';false'; cmd.RunCommand('Select INVERT'); cmd.RunCommand(cmdLine); cmd.RunCommand('Select INVERT'); if (!args.noheading) tmp = argValues.replace(/,/g, '\t') + '\r\n'; tmp += DOpus.vars.Get('columnValue'); } function Log(str) { if (args.nolog) return; cmd.RunCommand('Set UTILITY=scriptlog'); // DOpus.ClearOutput(); DOpus.Output('\n' + str); } }