Shortcut key or javascript code for "Create New Item from Current Page"

While I am eagerly awaiting for a shortcut key for the "Create New Item from Current Page" icon, I am just wondering can I do this using Zotero data/object API??

var Zotero = Components.classes[";1"]

What code should be inserted here that is equivalent to clicking "Create New Item from Current Page"?
  • You don't need the core XPCOM object at all. The "Create New Item from Current Page" functionality is in ZoteroPane.addItemFromPage(), which is available in the chrome window scope.

    (The main Zotero UI is specified in overlay.xul, and you can see there that the zotero-tb-item-from-page button calls ZoteroPane.addItemFromPage(). ZoteroPane is defined in overlay.js.)
  • Hi Dan,

    Thanks for the hints. I do not know much about Mozilla's XUL. With just some rudimentary skills in JavaScript I get most of my job done. So it was a bit hard to grasp the hint in full.

    However, I got some clue. I created and ran (via Chickenfoot FF Extension) the following script which accomplish my task for the time being:

    var Zotero = Components

    ZoteroPane.addAttachmentFromPage() //

    I'll appreciate if you or anybody could further refine the script so that it coud attach snapashot when creating an item from a web page.


  • First, "Create New Item from Current Page" uses addItemFromPage(), not addAttachmentFromPage(). addItemFromPage() follows the "Automatically create snapshots..." setting in the General pane of the Zotero prefs, so there's no need to create an attachment manually.

    Also, since ZoteroPane already exists in the chrome window scope and is designed to work in that scope, you don't want to include overlay.js yourself in Chickenfoot. Just grab the existing object in the front-most browser window:

    var wm = Components.classes[";1"]
    var browserWindow = wm.getMostRecentWindow("navigator:browser");

    But if you just want to assign a shortcut key, it's easier to grab the Keyconfig extension, create a new global shortcut, and use

    (and nothing more) as the script.

    I have incorporated your script into my Chickenfoot JavaScript that opens a 'printer friendly' URL, grabs the title of the article from an <h3> element and adds it to the <title> where it should actually have been. And then the above script finally saves the improved/rectified item to Zotero. All these tasks are automated with just one keystroke Alt+R (to run Chickenfoot script).

    Zotero and Chickenfoot are r/evolutionary tools/apps/frameworks that has changed the way we collect information and read. I gratefully appreciate all your great works and helps.

Sign In or Register to comment.