CopyQ icon indicating copy to clipboard operation
CopyQ copied to clipboard

Encrypt and copy to a specific tab with one shortcut

Open maxclac opened this issue 2 years ago • 3 comments

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

maxclac avatar Apr 27 '23 08:04 maxclac

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

hluk avatar Aug 21 '23 13:08 hluk

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.

maxclac avatar Aug 24 '23 13:08 maxclac

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

hluk avatar Aug 25 '23 05:08 hluk