By scripting, reorganise My Library with items in nested subcollections

I have just returned to using Zotero add-on for Firefox (40.0.3) on Ubuntu 14.04 after a long period of not using Zotero. I have arranged My Library as nested folders (sub-collections).

I hope to write a script (Python or Javascript?) to rearrange the nested My Library structure from time to time avoiding need for manual drag and drop of subcollection folders and items.

I was hoping to export the library tree structure into say JSON format, rearrange by some parsing of exported JSON file, then import the reordered tree structure and save revised library structure to remote server.

However when I preview the exported JSON (or other format) file it seems that the export does not output the full nested folder path to each item.

What is the recommended way of rearranging library structure by script .. not using drag and drop? Taking this as an example:-

> subcollection
--------> subcollection1
------------> item1
------------> item2
------------> item3
------------> item4
--------> subcollection2
------------> item1
------------> item2
------------> item3
------------> item4
--------> subcollection3
------------> item1
------------> item2
------------> item3
------------> item4

If I right click on any My Library folder and choose Export Collection I cannot find any export option which preserves the full subcollection paths in the exported file.

e.g subcollection > subcollection1 > item1

Searching for "reorganise library" I don't find much advice on this topic. The preferred practice seems to be to reorder the library by drag and drop operations in Zotero window.

So far I have read a few threads on using javascript and pyzotero.

I've now installed Execute JS add-on.

And I've found pyzotero if I have to use Zotero API.

Is my understanding of export/import options correct?

Are there options in sqlite for reorganising My Library? I would use sqlite in command line since I understand from threads in this forum that Firefox must be shut down first before any dabbling with sqlite.
  • Zotero RDF does include collection information for items, but import/export is not a good idea (it changes the unique IDs of your database, which messes with sync, LibreOffice integration and likely more; it's also not 100% lossless).

    The recommended way would probably be via the javascript API (make sure to back-up your library), though using the web API is possible, too.

    I'd strongly discourage doing this via sqlite (though that, too, is possible), as you can corrupt your library in ways that may not become immediately apparent.
  • Thanks for the tips.
    I've managed to run some Python scripts and I'll try Javascript API.

    But at this moment I have a more basic problem before I get to scripting.

    I seem to be unable to drag any item from middle pane into any collection in left pane.

    I click on My Library which lists all items in middle pane. I then highlight an item, and attempt to drag item left into a target collection or subcollection to rearrange My Library.

    Nor it seems can I manually drag folders around in the collection tree (left pane). This non working drag and drop feature is puzzling me.

    How do I apply basic drag 'n drop to items and tree nodes?

    I have sync disabled. I have Zutilo installed.
  • Let's start by dragging to collections on the left:
    1) Restart Zotero just to be safe
    2) Does the target collection highlight as you drag to it?
    3) And you've made sure items don't appear in the target collection (they obviously wouldn't disappear from My Library)?

    If 1 and 3, we'd want a debug ID for an attempt to drag an item:
  • I did experience being unable to drag into collection folder (to answer question 2 above the target collection was not highlighted). But I have since started a new Firefox session and this quirk has not come back. Target collection now highlights and item is copied.

    My confusion arises from the fact that I can drag and drop collections (to create a nested tree structure) but I cannot drag and drop items into collections. By drag and drop I mean copy item into target and then remove item from origin.

    I have read this old (2009) thread ...

    which confirms my own experience on drag and drop items into subcollections.

    I now understand that the practice is to copy the item to the target collection and then delete the item from the origin collection. This is not done automatically in Zotero.

    I'm now exploring the standalone version of Zotero which allows items across browsers (Firefox or Chrome) to be placed into Zotero database.
  • Moving of items works by pressing the shift key, and holding it down during the drag—it is discussed in a more recent thread.
  • You can move instead of copy items between collections via shift+drag (cmd+drag on Mac).

    For scripting, of course, there is no differences between Zotero for Firefox and the Standalone version.
  • Thanks for pointing this out.

    I didn't read the manual (as follows:).

    Adding Items to Collections

    New items are automatically saved into the selected collection.

    To assign existing items in your library to a collection, select them in the center column and drag them onto a collection. By default, the items will be added to the new collection but won't be removed from the original location.

    To move items between collections instead of simply adding them to the new collection, press and hold Cmd (OS X) or Shift (Windows/Linux) and then drag the item onto a collection. Items can only be moved between collections; since “My Library” always shows all items (other than those in the trash), it's not possible to move an item from “My Library” to a collection.


    Now back to automating this process by scripting (where I started this thread) ..
Sign In or Register to comment.