# ClipEdit (Modify the clipboard)

**URL:** https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636
**Category:** Buttons/Scripts
**Tags:** script, commands, jscript
**Created:** [June 14, 2023, 5:36pm UTC](https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636 "2023-06-14T17:36:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)
#### Post date: [June 14, 2023, 5:36pm UTC](https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636/1 "2023-06-14T17:36:58Z")

</div>

**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...

```plaintext
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:

```plaintext
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

```plaintext
C:\Program Files\Notepad++\notepad++.exe

```

into

```plaintext
%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

1️⃣ Save [CommandClipEdit.js.txt](https://resource.dopus.com/uploads/short-url/4y1UDEackXBL5jalBRrQhMn136V.txt) to

```
%appdata%\GPSoftware\Directory Opus\Script AddIns

```

2️⃣ Copy this menu to a toolbar or create your own buttons with **ClipEdit**.

> **Menu as XML**
>
> ```plaintext
> <?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&apos; 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&apos; 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](https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546)  
[What are aliases?](https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Aliases.htm)

#### The script's inner workings

> **JScript**
>
> ```javascript
> 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);
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![bytim](https://resource.dopus.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bytim](https://resource.dopus.com/u/bytim)
#### Post date: [February 19, 2025, 3:06pm UTC](https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636/2 "2025-02-19T15:06:28Z")

</div>

Error

![image](https://resource.dopus.com/uploads/default/original/3X/e/9/e9a07323b36e78c04957a4b2fbcfbdffb0a88e61.png)

I I changed the function code to this:

```auto
    function EditAlias() {
        for (var e = new Enumerator(DOpus.aliases); !e.atEnd(); e.moveNext()) {
            var item = e.item();
            //DOpus.Output(String(item) + "--" + item.path)
            if (String(item) == 'defaultright') continue;
            if (String(item) == 'lastright') continue;
            if (String(item) == 'onedrive') continue;
            if (String(item) == 'skydrive') continue;
            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;
            vec.push_back(item);
        }

```

```auto
    function EditAliasExpand() {
        for (var e = new Enumerator(DOpus.aliases); !e.atEnd(); e.moveNext()) {
            var item = e.item();
            if (String(item) == 'defaultright') continue;
            if (String(item) == 'lastright') continue;
            if (String(item) == 'onedrive') continue;
            if (String(item) == 'skydrive') continue;
            if (item.path.drive == 0) continue; // we skip /trash etc.
            vec.push_back(item);
        }

```

These 4 aliases defaultright, lastright, onedrive and skydrive have no path property.

---

<div class="post-metadata">

### Author: ![aZtraL](https://resource.dopus.com/user_avatar/resource.dopus.com/aztral/32/72568_2.png) [@aZtraL](https://resource.dopus.com/u/aZtraL)
#### Post date: [October 24, 2025, 12:47am UTC](https://resource.dopus.com/t/clipedit-modify-the-clipboard/44636/3 "2025-10-24T00:47:43Z")

</div>

Its safer and more future proof to check for the missing path object first since i believe more aliases can have unset paths at some point.

```javascript
function EditAlias() {
        Log("@EditAlias");
        for (var e = new Enumerator(DOpus.aliases); !e.atEnd(); e.moveNext()) {
            var item = e.item();

            if (!args.nolog) DOpus.Output("Alias: " + (item + Array(25 - String(item).length).join(" ")) + (!item.path ? "" : " " + item.path));

            if (!item.path || 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;
            if (String(item) == 'last') continue;
            if (String(item) == 'lastright') continue;
            if (String(item) == 'defaultright') continue;
            if (String(item) == 'default') 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);
        }
    }

```
