Closed ventolinmx closed 2 years ago
It seems that something is blocking the copy operation.
Does it always give the error? What's your OS?
Yes, i always get that error. Haven't been able to use that command. My OS is Debian 10 Buster.
What's your desktop environment? Any chance you're using Wayland and not X11?
It's Gnome 3.30.2 :)
Can you try running copyq copy TEST
from terminal to see if it copies "TEST" text to clipboard?
Yes, i get TEST copied to clipboard.
Can you check what's in the clipboard after the error "Failed to copy to clipboard"? You can inspect the clipboard from the main window in CopyQ with Ctrl+Shift+C default shortcut (menu bar: File - Show Clipboard Content).
Nothing, it is empty. A couple of seconds pass from pressing the shortcut of the command to the display of the error notification.
Ah, OK, I think the copy()
call (the one without argument) is failing. My guess is that the target app doesn't support copying using Ctrl+C (that's what CopyQ emulates) or the shortcut is not sent properly.
You can try using xdotool
utility to send shortcuts instead:
[Command]
Command="
copyq:
function modifyText(text)
{
// TODO: Modify text here!
return text.replace('\\n', ';')
}
function sendShortcut(shortcut)
{
// Wait for keyboard modifiers to be released.
// Alternative would be \"--clearmodifiers\" parameter for xdotool,
// but it can behave erratically.
while (queryKeyboardModifiers().length > 0) {
sleep(50);
}
var result = execute('xdotool', 'key', shortcut)
if (!result) {
throw 'Failed send shortcut ' + shortcut
}
if (result.exit_code != 0) {
throw 'Failed send shortcut ' + shortcut + ': ' + result.stderr
}
}
sendShortcut('ctrl+c')
var text = str(clipboard())
popup(text)
var newText = modifyText(text)
if (text == newText)
abort();
copy(newText)
sendShortcut('shift+Insert')"
GlobalShortcut=ctrl+shift+s
Icon=\xf15b
IsGlobalShortcut=true
Match=/\\/(?:)\\//
Name=Template: Modify Selected Text
Window=/\\/(?:)\\//
Before doing that i would like to try the script. Running it from the menu in order to bypass shortcuts i realized it only replaces the first occurrence. Why is this?
Thank you.
String.replace() function only replaces the first occurrence, unless you use regular expression.
text.replace(/\\n/g, ';')
I fixed the command to do this.
Great!! Now i can paste continuous text from pdfs formatted with line breaks or columns. I'll try the command with xdotool. I just need a little more time to figure that out. Thanks for your support.
Hi
Trying modify-selected-text.ini and getting the following error:
I would like to remove end of line replacing EOL with space.