wshanks / Zutilo

Zotero plugin providing some additional editing features
Other
1.51k stars 72 forks source link

Zutilo not recognizing files to modify attachment pathways #213

Open jrosecook opened 2 years ago

jrosecook commented 2 years ago

Hello,

I am trying to use Zutilo to batch modify the attachment pathways for my Zotero files. Unfortunately my files were stored in several different places (Zotero's storage and online in Box) before they got moved to a new folder in Box. (At the time, I did not have the relative pathways setting turned on - big mistake.)

In addition to the PDFs Zotero automatically downloads, I also have separate PDF files attached to most parent items that I have manually downloaded and edited; I keep those in a separate folder within Box. This hybrid workflow is definitely not the best system, but I like having a blank copy of readings and an edited copy. Sometimes I move the PDFs I manually download into thematic folders based on the research I am currently doing, although I am in the process of switching to using the Zotero metatags.

My issue is this: I am trying to relink my files en masse within Zotero using Zutilo. For a few of them, it has worked one-by-one. For most files, though, when I select "modify attachment paths", I get an error message that says "Zutilo: item selection error: Please select at least one eligible attachment item or one regular item with an eligible attachment." However, when I click on the item to open the PDF, I can see that it is definitely not linked in Zotero.

I have tried selecting both the parent item and the individual attachment when modifying the attachment path, and neither works.

I've read through a TON of tutorials on the Zotero forums and here, and nobody else seems to have had this issue. Any help would be much appreciated! I have over 1K files linked in Zotero, so it would really suck to have to reattach them all manually.

wshanks commented 2 years ago

Hmm, that is weird. Does anything show up in the error console (Tools->Developer->Error console)? Somehow the logic for detecting attachment items is not working for those items.

Here is some code based on Zutilo's code that you can try:

let output = {
    "title": [],
    "linkMode": [],
    "deduplicatedTitles": [],
}
let items = ZoteroPane.getSelectedItems()
let attachmentItems = []
for (let item of items) {
    if (item.isRegularItem()) {
        attachmentItems = attachmentItems.concat(Zotero.Items.get(item.getAttachments(false)))
    } else if (item.isAttachment()) {
        attachmentItems.push(item)
    }
}
for (let item of attachmentItems) {
    output.title.push(item.getDisplayTitle())
    output.linkMode.push(item.attachmentLinkMode)
}
for (let item of ZutiloChrome.zoteroOverlay.removeDuplicateItems(attachmentItems)) {
    output.deduplicatedTitles.push(item.getDisplayTitle())
}
output

You can paste that into the run javascript window (Tools->Developer->Run javascript) and use ctrl+r to run it with different items selected and see what it prints out. Linked file attachments should have link mode 2. Zutilo looks at the attachments of regular items and directly at attachment items for that mode. It gives the message you quoted when none are found to be selected. My code above should display the mode and title for each selected item (or its attachments) and then also display the deduplicated titles using Zutilo's deduplication function (just to check if somehow that is removing all the items).