hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.5k stars 438 forks source link

Encrypt and copy to a specific tab with one shortcut #2343

Open maxclac opened 1 year ago

maxclac commented 1 year ago

Hi!

I have created a new tab for encrypted items. What I would like is to be able to copy content from anywhere, encrypt it, and put it directly to this dedicated tab with one shortcut. I could not figure this out by reading the documentation. How can it be achieved?

Best regards

hluk commented 1 year ago

Try it with the following command (here is how to add the command to CopyQ):

[Command]
Command="
    copyq:
    const tabName = 'Secret';
    copy();
    const item = {}
    item[mimeText] = clipboard(mimeText);
    const encrypted = plugins.itemencrypted.encrypt(pack(item));
    tab(tabName);
    write('application/x-copyq-encrypted', encrypted);
    "
GlobalShortcut=meta+ctrl+c
Icon=\xf21b
IsGlobalShortcut=true
Name=Copy Secret
maxclac commented 1 year ago

Thank you for your answer. The problem with this solution is that the copied text also appears in the normal tab, not just in the encrypted tab.

hluk commented 1 year ago

The problem with this solution is that the copied text also appears in the normal tab, not just in the encrypted tab.

Ah, I think it requires disabling the clipboard storing momentarily (similarly to Copy a Secret command):

[Command]
Command="
    copyq:
    const tabName = 'Secret';

    const wasMonitoring = monitoring();
    if (wasMonitoring) disable();
    try {
        copy();
    } finally {
        if (wasMonitoring) enable();
    }

    const item = {}
    item[mimeText] = clipboard(mimeText);
    const encrypted = plugins.itemencrypted.encrypt(pack(item));
    tab(tabName);
    write('application/x-copyq-encrypted', encrypted);
    "
GlobalShortcut=meta+ctrl+c
Icon=\xf21b
IsGlobalShortcut=true
Name=Copy Secret