Bulk editing of titles - is it possible?

edited 18 days ago
I need to reformat a bibliography for a particularly persnickety journal.

I know that I can select an individual item in my Zotero library on my Mac, right click on the Title field and convert it to sentence case. But is there a way to do that for a whole group of items that I select?

I also know that I can add HTML tags to scientific names within an individual item in my library, so that they appear in italics. But is there a way to do a search and replace for a whole group of items, so as to add the tags without having to do each item individually?
  • For the species names, you can use Zotero's JavaScript API to search for the name, then replace it with the name+tags:

    It might also be possible to use the JavaScript API to mass-convert titles to sentence case (you should always store titles in sentence case), but you will want to be careful there to check for proper casing of words afterward (e.g., the genus name).

    @dstillman Is the sentence-casing function available in the JavaScript API?
  • @bwiernik thanks for the link!
  • edited 18 days ago
    @bwiernik the code for the sentence-casing is at https://github.com/zotero/zotero/blob/master/chrome/content/zotero/bindings/itembox.xml#L2075 . You can't call it directly (code living inside XBL is a real PITA to reach into) but it's just two lines.
  • (and for a specific use case, you could do much better than Zotero's default sentence case code, e.g. by adding some exceptions, e.g. for genus names.
  • This is the script I've written to preserve words with uppercase letters other than the first.

    zoteroPane = Zotero.getActiveZoteroPane();
    items = zoteroPane.getSelectedItems();
    var result = "";
    for (item of items) {
    var title = item.getField('title');
    result += " " + title + "\n";
    var new_title = title.replace(/\b([A-Z][a-z0-9]+|A)\b/g, function (x) { return x.toLowerCase(); });
    new_title = new_title.replace(/(^|\?\s*)[a-z]/, function (x) { return x.toUpperCase(); });
    result += "-> " + new_title + "\n\n";
    // // Do it at your own risk
    // item.setField('title', new_title);
    // await item.saveTx();
    return result;

Sign In or Register to comment.