Contact

Subscribe via Email

Subscribe via RSS/JSON

Categories

Creative Commons Attribution 4.0 International License
© Rakhesh Sasidharan

Elsewhere

Search Firefox bookmarks using PowerShell

I was on Firefox today and wanted to search for a bookmark. I found the bookmark easily, but unlike Chrome Firefox has no way of showing which folder the bookmark is present in. So I created a PowerShell script to do just that. Mainly because I wanted some excuse to code in PowerShell and also because it felt like an interesting problem.

PowerShell can’t directly control Firefox as it doesn’t have a COM interface (unlike IE). So you’ll have to manually export the bookmarks. Good for us the export is into a JSON file, and PowerShell can read JSON files natively (since version 3.0 I think). The ConvertFrom-JSON cmdlet is your friend here. So export bookmarks and read them into a variable:

This gives me a tree structure of bookmarks.

Notice the children property. It is an array of further objects – links to the first-level folders, basically. Each of these in turn have links to the second-level folders and so on.

The type property is a good way of identifying if a node is a folder or a bookmark. If it’s text/x-moz-place-container then it’s a folder. If it’s text/x-moz-place then it’s a bookmark. (Alternatively one could also test whether the children property is $null).

So how do we go through this tree and search each node? Initially I was going to iteratively do it by going to each node. Then I remembered recursion (see! no exercise like this goes wasted! I had forgotten about recursion). So that’s easy then.

  • Make a function. Pass it the bookmarks object.
  • Said function looks at the object passed to it.
    • If it’s a bookmark it searches the title and lets us know if it’s a match.
    • If it’s a folder, the function calls itself with the next level folder as input.

Here’s the function:

I decided to search folder names too. And just to distinguish between folder names and bookmark names, I use different colors.

Call the function thus (after exporting & reading the bookmarks into a variable):

Here’s a screenshot of the output:

search-fxbookmarks

[Aside] AdBlock Plus

Came across this report yesterday. Turns out AdBlock Plus (ABP) increases memory usage due to the way it works. Check out this post by a Mozilla developer for more info. The latter post also includes responses from the ABP developer. 

I disabled ABP on my browsers. Not because of these reports, but because I had been thinking of disabling it for a while but never got around to it. (I know it’s just a right click and disable away, but I never got around to it! :) Mainly coz I use the excellent Ghostery and Privacy Badger extensions, and these block most of the trackers and widgets I am interested in blocking, so I have never used ABP much. I had installed it a long time ago and it gets installed automatically on all my new Chrome/ Firefox installs thanks to sync, but I never configure or bother with it (except to whitelist a site if I feel ABP could be causing issues with it). Yesterday’s report seemed to be a good excuse to finally remove it. 

This Hacker News post is also worth a read. There are some alternatives like µBlock (seems to be Chrome only) (github link). It is based on HTTP Switchboard and is by the same developer. I have used HTTP Switchboard briefly in the past. Came across it as I was looking for a NoScript equivalent for Chrome and this was recommended. I didn’t use it much though as there was too much configuring and white-listing to do. (For that matter I stopped using NoScript too. It’s still installed but disabled except for its XSS features). Like I said, my favorites now are Ghostery and Privacy Badger – the latter is especially smart in that automatically starts blocking websites based on your browsing patterns (in fact Privacy Badger is based on ABP).