Skip to content

Instantly share code, notes, and snippets.

@davebraze
Last active June 26, 2023 06:09
Show Gist options
  • Save davebraze/79ae3286d07a880711ca640f4fdee14e to your computer and use it in GitHub Desktop.
Save davebraze/79ae3286d07a880711ca640f4fdee14e to your computer and use it in GitHub Desktop.
// https://www.zotero.org/support/dev/client_coding/javascript_api
// My immediate goal is to batch edit Zotero tags. Things I'd like to be able to do include:
// o normalize case (e.g., make all tags lower case)
// o remove extraneous characters from beginning or end of tags (e.g., "*" or ",")
// o get a list of tags used exactly once (save to file)
// run synchronously
var zp = Zotero.getActiveZoteroPane();
var keys = Object.keys(zp);
keys;
// get active sort-by field
zp.getSortField();
// like it says
zp.getSortDirection();
// get items in library or group as an array [], sorted by active sort field
zp.getSortedItems();
// get selected items as an array []
zp.getSelectedItems();
/////////////// Seems I'll need to access the `Zotero` object to work with tags
var zoteroKeys = Object.keys(Zotero)
zoteroKeys;
Object.keys(Zotero.Tags)
Zotero.Tags.getAll() // returns a promise; I don't know what to do with that
// takes a case-sensitive string (a tag name) as an argument and returns a numerical tagID or 'false' if there is no match
Zotero.Tags.getID("entropy")
// takes a numerical tagID and returns the associated tag name
Zotero.Tags.getName(8849)
// requires a 'tagID' as an argument
/*
// the return value is inintuitive (to me):
{
"isFulfilled": false,
"isRejected": true,
"rejectionReason": {}
}
*/
///////////////// other stuff to dig in to
Zotero.Tags.rename(Zotero.Libraries.userLibraryID, tag, newTag)
Zotero.Tags.getColors(libraryID)
Zotero.Tags.setColor(libraryID, name, false)
Zotero.Tags.equals(data1[i], data2[i])
Zotero.Tags.equals(c1.value, c2.value))
Zotero.Tags.getAutomaticInLibrary(libraryID)
Zotero.Tags.create()
Zotero.Tags.getLongTagsInLibrary(libraryID)
Zotero.Tags.getAsync(id)
Zotero.Tags.getAllWithin({ tmpTable: results, types, tagIDs })
Zotero.Tags.purge()
Zotero.Tags.cleanData(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment