[Share] Copy DOI to Clipboard #397
rodrigolourencofarinha
started this conversation in
Action Scripts
Replies: 3 comments 1 reply
|
https://github.com/windingwind/zotero-actions-tags?tab=readme-ov-file#custom-script Please always use the items instead of ZoteroPane.getSelectedItems(). The action can be triggered from entrances outside the library, where the items are not from ZoteroPane. |
0 replies
|
The script above does not work for me (if I select one item, the DOI is visible in my clipboard history, if I select several items nothing is visible in the history ; in any case doing I am using Zotero var doiArray = [];
for (let item of items) {
if (item.isRegularItem() && !(item instanceof Zotero.Collection)) {
let doi = item.getField('DOI');
if (doi && !doiArray.includes(doi)) {
doiArray.push('https://doi.org/'+doi);
}
}
}
// Create a string with a comma after each DOI except the last one
var clipboardText = doiArray.map((doi, index) => {
return index < doiArray.length - 1 ? doi + ',' : doi;
}).join('\r\n');
Zotero.Utilities.Internal.copyTextToClipboard(clipboardText);
// Tried this way, didn't work either
// const clipboard = new Zotero.ActionsTags.api.utils.ClipboardHelper();
//clipboard.addText(clipboardText);
//clipboard.copy();
// This does return the correct DOI(s), so the issue seems to be with copying to clipboard
return clipboardText; |
1 reply
|
I wrote a script aiming at the same goal, but it wound up diverging substantially enough that I've posted it as a new [Share] (#624). |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description
This script extracts DOIs from the currently selected Zotero items, formats them with a comma after each DOI (except the last), and copies the resulting list to the clipboard for easy use in other applications.
Event
None
Operation
Script
Data
Anything else
No response
All reactions