Copying Multiple Attachment Paths at Once #435
-
Does anyone know what the JS code would be for copying-to-clipboard all attachment paths, from multiple selected items, all at once (with each attachment path on a new line)? I've found #404, which provides the JS code for copying-to-clipboard one attachment path from one selected item. I would love to be able to copy multiple attachment paths at once, so that I can feed them into a script for searching pdfs. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I used ChatGPT to generate the following code, which allows me to copy-to-clipboard all attachment paths, from multiple selected items, all at once (with each attachment path on a new line): if (!items?.length) return; async function getAttachmentPath(item) { if (item.isAttachment() && !item.isNote()) { return await item.getFilePathAsync(); } else if (item.isRegularItem() && !item.isAttachment()) { let attachment = await item.getBestAttachment(); return attachment ? await attachment.getFilePathAsync() : null; } return null; } (async () => { try { // Retrieve all file paths asynchronously const filePaths = await Promise.all(items.map(getAttachmentPath)); // Filter out null or undefined paths const nonNullPaths = filePaths.filter(Boolean); if (nonNullPaths.length) { // Copy all paths to the clipboard, separated by newlines Zotero.Utilities.Internal.copyTextToClipboard(nonNullPaths.join('\n')); Zotero.debug(`Copied ${nonNullPaths.length} file paths to clipboard.`); } else { Zotero.debug('No file paths found to copy.'); } } catch (error) { Zotero.debug('An error occurred while processing items: ' + error); } })(); |
Beta Was this translation helpful? Give feedback.
I used ChatGPT to generate the following code, which allows me to copy-to-clipboard all attachment paths, from multiple selected items, all at once (with each attachment path on a new line):