Last active
August 4, 2022 02:09
-
-
Save 0/1cd0bff653a829d79145676d5b1ede03 to your computer and use it in GitHub Desktop.
Script to convert Zotero items from Journal Article to Preprint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Previously, preprints were added to Zotero as items of the "Journal Article" | |
* type, but it now has a dedicated "Preprint" item type. This script finds all | |
* articles that look like arXiv preprints and converts them to the new type. If | |
* your items have categories in the publication name, you may need to remove | |
* them. | |
* | |
* Select all the articles you want to convert, go to Tools -> Developer -> Run | |
* JavaScript, check "Run as async function", paste this script on the left side, | |
* and press "Run". It may take a while, but eventually the right side should | |
* display a summary of all the affected items. | |
* | |
* There doesn't appear to be any way to undo this process, so you should make a | |
* backup of your library, and test this script on a single article first. | |
*/ | |
const selectedItems = ZoteroPane.getSelectedItems(); | |
const titles = []; | |
for (const item of selectedItems) { | |
if (item.getType() != Zotero.ItemTypes.getID('journalArticle')) { | |
continue; | |
} | |
if (!item.getField('publicationTitle').startsWith('arXiv:')) { | |
continue; | |
} | |
const archive_id = item.getField('publicationTitle'); | |
item.setType(Zotero.ItemTypes.getID('preprint')); | |
item.setField('repository', 'arXiv'); | |
item.setField('archiveID', archive_id); | |
await item.saveTx(); | |
titles.push(archive_id + ': ' + item.getField('title')); | |
} | |
return titles.join('\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment