Rename parent item from attachment name

I have a lot of pdf documents for which metadata is nonexistant.

As I understand it zotero does not read metatata from pdf file but searches for metadata from web translators. This option is not availible for these documents.

I can batch create items for documents with zotfile, and copy item fields from "template item" I created to these items. All I have to do now is name the items whith the name of the attachment, which is prepared to my liking. I would like to perform this in a batch process.

Is there an option to rename item from the attachment filename (there is only one attachment per item).

Can this be done with JavaSript console in zotero or could I modify zutilo to do this.

I guess what am I asking is if a plugin or JS console can access local javascript api to make appropriate changes.
  • When you make a parent item with the Create Parent Item function, it sets the title to be the file name of the attachment. If that is already what you want, you’re good to go.

    If you have more than the title in the file name but entered in a structured format, you could use the Run JavaScript console from the Tools menu with regex to extract the variables and assign them to the item fields.

    You can see some examples of the JS api for batch editing that you can adapt here https://www.zotero.org/support/dev/client_coding/javascript_api

    Let us know if you need more details.
  • tnx.
    First time I made items with zotfile it didn't work, I got blanks.

    I tried for a single item, as you suggested, got the prompt, enter, and parent item was renamed.

    Now it works also for multiple items in zotfile. Dont know why it didn't work the first time.
  • @Dalek
    I have many attachments whose metadata retrieval failed, so I'm left with many parent items with useless names. I'd like to rename them as the filenames. I am trying to use Zotfile to do this, as you seem to have done, but can't figure it out. Could you please explain how this works?

    Thanks!
  • You can't use Zotfile on items not attached to any metadata.
  • edited May 8, 2021
    Sorry, I wasn't clear. I added a lot of attachments, then created parent items, then retrieved metadata. Some parent item metadata titles are useless, so I'd like to set the title to the linked filename. Is this possible in any way? I got the impression that @Dalek was able to do this with Zotfile
  • I have many attachments whose metadata retrieval failed, so I'm left with many parent items with useless names. I'd like to rename them as the filenames.
    @seeingtheforest: You could try this:

    A. Separate pdf attachments from parent items:

    1. Add items with bad parent metadata to a collection, e.g., "FixParentMeta"

    2. Quick search ("All Fields & Tags"): .pdf

    3. Click on one item in the middle/central pane

    4. Edit -> Select All (or Ctrl+A): This selects only pdf attachments

    5. Drag all pdf attachments away from the parent items; clear the quick search field

    B. Delete bad parent items without attachments

    C. Create new parent items from attachments:

    1. Select all pdf files

    2. Right click -> "Create Parent Item"

    The new parent items have the filename in their Title field.
  • For structured filenames, see this discussion: https://forums.zotero.org/discussion/89460/importing-files-with-structured-filenames-title-author-year-pdf

    (You could drag the attachments out of Zotero and import them again through a RIS file.)
  • edited May 8, 2021
    @qqbb

    Wow, I didn't know you could separate/remove attachments from parents like that - I thought they were "stuck" with their parent once "born"! The only problem is that I want to maintain the collection/folder structure that I have set up - the files are spread across 200+ collections.

    What I've started to do is the following:
    1. Create a tag and assign it a color and 1-9 hotkey
    2. Select the items that I want to process and tag them with the #
    3. Change Zotfile's advanced setting "extensions.zotfile.disable_renaming" to "true" so that it doesn't rename files when it moves them.
    4. Set Zotfile's Location to another folder and check "Use subfolder defined by" and set to "/%c" (the placeholder for collection subfolder)
    5. Filter library for the tag, Select all, Right Click, Manage Attachments->Rename attachments. All files are now moved to a new folder with subfolders mirroring the collections structure
    6. Delete them all from Zotero
    7. Using the "Folder Import for Zotero" add-on (https://github.com/retorquere/zotero-folder-import) import the folder and subfolders back into Zotero, presumably putting them all into the pre-existing collections.

    I haven't gone through the full workflow yet (still tagging), but I don't see why it won't work. I'll test on a small portion first, I suppose. But it would be mighty nice if there was just a menu item that is the opposite of "Rename File from Parent Metadata"...
  • 7. Using the "Folder Import for Zotero" add-on […], presumably putting them all into the pre-existing collections.
    Most likely, this will create new collections with the same names. You will have duplicated collection trees.
  • Thanks, I'll confirm later.
  • I'm pretty sure about that. There's no reason why existing collections would be used.

    If you want to keep the parent items, you could use the Zutilo add-on to clear all item metadata. Add all bad parent items to a collection. Then create a new empty item. Use Zutilo's "Copy item fields" on it, then select the other items and use "Paste all item fields". This will clear all bad parent metadata. See here for more details.

    After that, you could use a script to put back parent item titles using the attachment titles or filenames.
  • Yeah, it created duplicate collections. Not the end of the world... at least I can relatively easily drag to the originals and delete the duplicate ones.
Sign In or Register to comment.