ClipEdit modifies the clipboard. The type of edit is determined by parameters. All edits are global (for the entire clipboard). You need to check the log panel or paste the clipboard somewhere to see the results.
Parameters
ClipEdit ALIAS
Replaces all paths with Opus' aliases, both built-in and user-defined.
This is the clipboard before...
First path C:\Users\Alexander\AppData\Roaming\GPSoftware\Directory Opus\Script AddIns\CommandClipEdit.js and
now the second C:\Users\Alexander\bin\exiftool\exiftool.exe and the third C:\Program Files\Notepad++\notepad++.exe
Yeah!
... and after applying the command:
First path /scripts\CommandClipEdit.js and
now the second /bin\exiftool\exiftool.exe and the third /programfiles\Notepad++\notepad++.exe
Yeah!
ClipEdit ALIASEXPAND
Converts all aliases to the underlying filesystem notation.
ClipEdit ENVVAR
Replaces all paths with Windows' environment variables.
Turns
C:\Program Files\Notepad++\notepad++.exe
into
%programfiles%\Notepad++\notepad++.exe
ClipEdit ENVVAREXPAND
Converts all environment variables to the underlying filesystem notation.
ClipEdit GENERIC
Converts curly quotation marks into straight single or double quotes. Serves mostly as encouragement for you to create your own replacement commands with JScript.
ClipEdit ISODATE
Converts date strings from D.M.YYYY into YYYY-MM-DD. Again, more of a demo and encouragement
NOLOG
Append to suppress logging in the log panel.
How to set up and use
Save CommandClipEdit.js.txt to
%appdata%\GPSoftware\Directory Opus\Script AddIns
Copy this menu to a toolbar or create your own buttons with ClipEdit.
Menu as XML
<?xml version="1.0"?>
<button backcol="none" display="both" dropdown_glyph="yes" label_pos="right" textcol="none" type="menu">
<label>ClipEdit</label>
<icon1>#edit</icon1>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Alias</label>
<tip>Replaces all paths with Opus' aliases</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit ALIAS</instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Alias Expand</label>
<tip>Converts all aliases to the underlying filesystem notation</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit ALIASEXPAND</instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Env Var</label>
<tip>Replaces all paths with Windows' environment variables</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit ENVVAR </instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Env Var Expand</label>
<tip>Converts all environment variables to the underlying filesystem notation</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit ENVVAREXPAND</instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Generic</label>
<tip>Converts curly quotation marks into straight single or double quotes</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit GENERIC</instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>ISO Date</label>
<tip>Converts dates from D.M.YYYY into YYYY-MM-DD</tip>
<icon1>#edit</icon1>
<function type="normal">
<instruction>ClipEdit ISODATE </instruction>
</function>
</button>
</button>
Things you might enjoy reading
How to use buttons and scripts from this forum
What are aliases?
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'ClipEdit';
initData.version = '2023-06-14';
initData.url = 'https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636';
initData.desc = 'Modify the clipboard';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddCommands(addCmdData) {
var cmd = addCmdData.AddCommand();
cmd.name = 'ClipEdit';
cmd.method = 'OnClipEdit';
cmd.template = '' +
'alias/s,' +
'aliasexpand/s,' +
'envvar/s,' +
'envvarexpand/s,' +
'generic/s,' +
'isodate/s,' +
'nolog/s';
cmd.hide = false;
cmd.icon = 'script';
}
function OnClipEdit(scriptCmdData) {
var cmd = scriptCmdData.func.command;
var args = scriptCmdData.func.args;
var fsu = DOpus.FSUtil();
var wld = fsu.NewWild();
cmd.deselect = false;
if (DOpus.GetClipFormat() != 'text') return;
var tmp = DOpus.GetClip();
var vec = DOpus.Create().Vector();
if (false);
else if (args.alias) EditAlias();
else if (args.aliasexpand) EditAliasExpand();
else if (args.envvar) EditEnvvar();
else if (args.envvarexpand) EditEnvvarExpand();
else if (args.generic) EditGeneric();
else if (args.isodate) EditIsodate();
Log(tmp);
DOpus.SetClip(tmp);
// ====
function EditAlias() {
for (var e = new Enumerator(DOpus.aliases); !e.atEnd(); e.moveNext()) {
var item = e.item();
if (item.path.drive == 0) continue; // we skip /trash etc.
if (String(item) == 'altstartup') continue;
if (String(item) == 'commonaltstartup') continue;
if (String(item) == 'commonfavorites') continue;
if (String(item) == 'commonprogramfiles') continue;
if (String(item) == 'commonprogramfilesx86') continue;
if (String(item) == 'desktopdir') continue;
if (String(item) == 'hostdocuments') continue;
if (String(item) == 'hostmusic') continue;
if (String(item) == 'hostpictures') continue;
if (String(item) == 'hostvideos') continue;
if (String(item) == 'skydrive') continue;
vec.push_back(item);
}
BubbleSort('/'); // bubble sort aliases by *path* length to achieve maximum replacement
for (var e = new Enumerator(vec); !e.atEnd(); e.moveNext()) {
var item = e.item();
var re = new RegExp(wld.EscapeString(item.path, 'r'), 'gmi');
var al = '/' + item;
tmp = tmp.replace(re, al);
}
}
function EditEnvvar() {
vec.push_back('%allusersprofile%');
vec.push_back('%appdata%');
vec.push_back('%commonprogramfiles%');
vec.push_back('%commonprogramfiles(x86)%');
vec.push_back('%comspec%');
vec.push_back('%driverdata%');
vec.push_back('%localappdata%');
vec.push_back('%onedrive%');
// vec.push_back('%onedriveconsumer%');
vec.push_back('%programdata%');
vec.push_back('%programfiles%');
vec.push_back('%programfiles(x86)%');
// vec.push_back('%programw6432%');
vec.push_back('%public%');
vec.push_back('%systemroot%');
vec.push_back('%temp%');
// vec.push_back('%tmp%');
vec.push_back('%userprofile%');
vec.push_back('%windir%');
BubbleSort(''); // bubble sort variables by *path* length to achieve maximum replacement
for (var e = new Enumerator(vec); !e.atEnd(); e.moveNext()) {
var item = e.item();
var re = new RegExp(wld.EscapeString(fsu.Resolve(item), 'r'), 'gmi');
var al = item;
tmp = tmp.replace(re, al);
}
}
function EditAliasExpand() {
for (var e = new Enumerator(DOpus.aliases); !e.atEnd(); e.moveNext()) {
var item = e.item();
if (item.path.drive == 0) continue; // we skip /trash etc.
vec.push_back(item);
}
BubbleSort(''); // bubble sort aliases by *name* length to achieve maximum replacement
for (var e = new Enumerator(vec); !e.atEnd(); e.moveNext()) {
var item = e.item();
var re = new RegExp('/' + item, 'gmi');
var al = fsu.Resolve('/' + item);
tmp = tmp.replace(re, al);
}
}
function EditEnvvarExpand() {
vec.push_back('%allusersprofile%');
vec.push_back('%appdata%');
vec.push_back('%commonprogramfiles%');
vec.push_back('%commonprogramfiles(x86)%');
vec.push_back('%comspec%');
vec.push_back('%driverdata%');
vec.push_back('%localappdata%');
vec.push_back('%onedrive%');
vec.push_back('%onedriveconsumer%');
vec.push_back('%programdata%');
vec.push_back('%programfiles%');
vec.push_back('%programfiles(x86)%');
vec.push_back('%programw6432%');
vec.push_back('%public%');
vec.push_back('%systemroot%');
vec.push_back('%temp%');
vec.push_back('%tmp%');
vec.push_back('%userprofile%');
vec.push_back('%windir%');
// BubbleSort(''); // sorting not needed here
for (var e = new Enumerator(vec); !e.atEnd(); e.moveNext()) {
var item = e.item();
var re = new RegExp(wld.EscapeString(item, 'r'), 'gmi');
var al = fsu.Resolve(item);
tmp = tmp.replace(re, al);
}
}
function EditGeneric() {
tmp = tmp.replace(/โ|โ/gm, '\'');
tmp = tmp.replace(/โ|โ|โ|ยป|ยซ/gm, '"');
tmp = tmp.replace(/โฆ/gm, '...');
// tmp = tmp.replace(/,/gm, ' ');
// tmp = tmp.replace(/(_|\')/gm, ' ');
}
function EditIsodate() {
tmp = tmp.replace(/(\d|\d\d)\.(\d|\d\d)\.(19|20)(\d\d)/g, '$3$4-$2-$1');
tmp = tmp.replace(/(19|20)(\d\d)-(\d)-(\d|\d\d)/g, '$1$2-0$3-$4');
tmp = tmp.replace(/(19|20)(\d\d)-(\d\d)-(\d)(\D|$)/g, '$1$2-$3-0$4');
}
function BubbleSort(prefix) {
for (var i = 0; i < vec.count - 1; i++) {
for (var j = i + 1; j < vec.count; j++) {
var k = String(fsu.Resolve(prefix + vec(i))).length;
var l = String(fsu.Resolve(prefix + vec(j))).length;
if (k >= l) continue;
vec.exchange(i, j);
}
}
}
function Log(str) {
if (args.nolog) return;
cmd.RunCommand('Set UTILITY=otherlog');
DOpus.Output('\n' + str);
}
}