-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command for selecting, copying and pasting multiple file clipboard entries at once #751
Comments
Could be done with the command below (add it to CopyQ). [Command]
Command="
copyq:
var len = length()
var uriList = ''
for (var i = 0; i < len; ++i) {
var path = str(read(mimeUriList, i))
if (path)
uriList += path + '\\n'
}
if (!uriList) {
popup('No files available to paste')
abort()
}
copy(mimeUriList, uriList)
paste()"
GlobalShortcut=meta+alt+f
Icon=\xf114
Name=Paste All Files But this pastes all files found in the first tab, maybe it would be better to stop at the first item which isn't a file. Not sure what your use case is. |
Thanks for this Assuming CopyQ is empty, my use case is to use the standard Ctrl + C ability in Windows to add multiple files from multiple locations to the CopyQ clipboard one at a time. I would then jump to CopyQ and using a custom command paste all the files I had in the clipboard to my current window. Would that work? It's effectively using CopyQ as a basket/queue system to prevent having to copy and paste each file one at a time.
With this command, I would expect to skip anything that isn't a file. Only interested in file objects that are in the clipboard. |
The command can be used without opening the application window. Just set the shortcut to whatever you like. Pressing the shortcut copies all files in CopyQ and pastes them to current window. |
|
Seems that the target app is ignoring Shift+Insert (the default shortcut for pasting). To use Ctrl+V instead you have to change it manually in config file (see this comment; config file on Linux is |
Appreciate your help I'm on Windows so I added As a side, it would also be good if only unique paths were allowed otherwise running the command several times will result in duplicate paths being copied to the clipboard. |
You can try putting an interval before pasting (e.g. [Command]
Command="
copyq:
var len = length()
var uriList = ''
for (var i = 0; i < len; ++i) {
var path = str(read(mimeUriList, i))
if (path)
uriList += path + '\\n'
}
if (!uriList) {
popup('No files available to paste')
abort()
}
copy(mimeUriList, uriList)
sleep(500)
paste()"
GlobalShortcut=meta+alt+f
Icon=\xf114
Name=Paste All Files BTW, which file manager do you use? |
By file manager do you mean what mechanism handles the file copying and pasting? I recently switched from the standard Windows 10 mechanism to Teracopy.
Any suggestions on how to achieve this? Tried switching to an array and then using |
To paste clipboard, CopyQ only tries to send the shortcut to active window. There is probably lot of apps where this doesn't work (timing is off when simulating key presses, the shortcut is send to different widget, app uses an incompatible way of capturing keys etc.). There could be a better way to do this on Windows but it's not critical enough for me now so someone else needs to implement this. Alternatively you can use an external app to paste the clipboard (e.g. instead of
Can you share the code? |
How it Works - "Paste All Files"
ℹ️ Please note the F2 key has been allocated in CopyQ to do the copying part whilst Ctrl + Alt + v is used in Autohotkey to do the pasting part.
[Command]
Name=Paste All Files
Command="
copyq:
var itemsLength = length(),
itemRowNumbers = [],
paths = [],
uriList = '',
fileTotal = 0
for (var i = 0; i < itemsLength; ++i) {
var path = str(read(mimeUriList, i))
if (path) {
var files = path.split('\\n')
for (var j = 0; j < files.length; ++j) {
path = files[j]
// Check path has not been added before
if (paths.indexOf(path) === -1) {
uriList += path + '\\n'
paths.push(path)
++fileTotal
}
}
itemRowNumbers.push(i)
}
}
if (!uriList) {
popup('No files available to copy')
abort()
} else {
popup('Pasting ' + fileTotal + ' file' + (fileTotal > 1 ? 's' : ''))
copy(mimeUriList, uriList)
// Remove all items after copying
// Must be done backwards
i = (itemsLength - 1)
while (i >= 0) {
if (itemRowNumbers.indexOf(i) !== -1) {
remove(i)
}
i--
}
}"
Icon=\xf114
GlobalShortcut=f2
!^v:: ; Ctrl-Alt-v
Send {F2} ; Function F2 key
Sleep 500
Send ^v ; Ctrl-v
Sleep 500
clipboard = ; Clear the clipboard
Return If CopyQ's |
Nice! Thanks for sharing. |
Relating to issue #234, I have a follow up query.
In the issue, instructions were given on how to copy multiple files:
The text was updated successfully, but these errors were encountered: