#!/usr/bin/python # Print the current tabs from a Firefox sessionstore.js file. # This lets me see what I've got open even if Firefox isn't running, or # I don't have access to the display. # Adam Sampson import os, sys, json, glob def dump(fn): f = open(fn) data = json.load(f) f.close() for win in data["windows"]: for tab in win["tabs"]: entries = tab["entries"] if entries == []: continue # This can contain forward history as well. # The entry with the "scroll" attribute appears to be # the currently-visible entry. current = tab["entries"][-1] for entry in entries: if "scroll" in entry: current = entry s = ("%s\n %s\n" % (current.get("title", "(no title)"), current.get("url", "(no URL)"))) s = s.encode("ASCII", "xmlcharrefreplace") sys.stdout.write(s) if __name__ == "__main__": if len(sys.argv) > 1: for fn in sys.argv[1:]: dump(fn) else: # Try to find the default profile's sessionstore.js. fn = glob.glob(os.environ["HOME"] + "/.mozilla/firefox/*default/sessionstore.js")[0] dump(fn)