{"size": 1458, "ext": "js", "max_stars_repo_path": "ff-addon/lib/main.js", "max_stars_repo_name": "Pancia/bookmark-manager", "max_stars_repo_stars_event_min_datetime": "2015-03-24T07:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2015-03-24T07:57:57.000Z", "max_issues_repo_path": "ff-addon/lib/main.js", "max_issues_repo_name": "Pancia/bookmark-manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ff-addon/lib/main.js", "max_forks_repo_name": "Pancia/bookmark-manager", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 38.3684210526, "max_line_length": 103, "alphanum_fraction": 0.6858710562}
var {Cc, Ci, Cu, Cr} = require("chrome");

Cu.import("resource://gre/modules/FileUtils.jsm");
var env = Cc["@mozilla.org/process/environment;1"]
            .getService(Ci.nsIEnvironment);
var shell = new FileUtils.File("/Users/pancia/Bookmarks/dist/build/bookmark-manager/bookmark-manager");

Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
var bookmarkService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]
                        .getService(Ci.nsINavBookmarksService);
var tagService = Cc["@mozilla.org/browser/tagging-service;1"]
                   .getService(Ci.nsITaggingService);
var IOService = Cc["@mozilla.org/network/io-service;1"]
                .getService(Ci.nsIIOService);

var bookmarkObserver = {
  onItemAdded: function(id, folder, i) {
    var url = bookmarkService.getBookmarkURI(id).spec;
    console.log("added ", url);
    var uri = IOService.newURI(url, null, null);
    console.log("with tags: ", tagService.getTagsForURI(uri, {}));
    var args = ["-s", "unix", "-f", "/Users/pancia/Bookmarks/bms.db"];
    var process = Cc["@mozilla.org/process/util;1"]
        .createInstance(Ci.nsIProcess);
    process.init(shell);
    process.runAsync(args, args.length);
  },
  QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
};

exports.main = function() {
  bookmarkService.addObserver(bookmarkObserver, false);
};

exports.onUnload = function() {
  bookmarkService.removeObserver(bookmarkObserver);
}
