Add tag to items from a list of authors?

Would there be any way to tag items in my library from a list of authors?

For example, I’d have a file authors.txt looking like:

Smith, John
Einstein, Albert
...

and I would want every item where these authors appear in my library to be tagged with some specific tag.

Is there a way I could do that?
  • edited July 2, 2022
    Use something like this in Tools → Run JavaScript:

    var file = '/Users/dan/Desktop/authors.txt';

    var s = new Zotero.Search;
    s.libraryID = ZoteroPane.getSelectedLibraryID();
    s.addCondition('joinMode', 'any');

    var file = await Zotero.File.getContentsAsync(file);
    var lines = file.split(/\n/);
    for (let line of lines) {
    // Split at comma and reverse order
    let names = line.split(/,\s*/);
    let name = (names[1] + ' ' + names[0]).trim();
    s.addCondition('creator', 'contains', name);
    }
    var itemIDs = await s.search();
    ZoteroPane.selectItems(itemIDs);


    Then drag the selected items to a tag in the tag selector.
  • edited July 3, 2022
    Thank you @dstillman, really appreciated. I’m going to test the script this afternoon ; however I might run into a problem: sometimes authors have middle names, first name is abbreviated (only the first letter), or missing accents. Would there be any way to prevent these problems and allow the script to find the items anyway? I assume the middle name problem would be easier to fix while there wouldn’t be any easy solution for the abbreviated names/missing accents. What do you think? I was thinking using only the last name but it might generate too many false positives.
Sign In or Register to comment.