Wednesday, June 6, 2012

How to Have Bookmark Tags in Chrome/Chromium

Probably the thing I've missed the most since changing to Chrome as my primary browser, is the bookmark tags. As with many innovations, I didn't see much use for them at first. But after I tried them out a little, I realized how powerful a tool they are. No more stopping to decide which folder or subfolder to bookmark a url in. Just a few quick tags to describe it and I'm done. I quickly learned how to do it without even touching my mouse.

Unfortunately, however, I found Firefox overall to be getting pretty buggy, and crashing far too often. Not to mention how slow it was getting. I swapped back and forth at first, hoping Mozilla would show the innovative flare they once had, and get caught up. But in the end, Chrome's simplicity and speed won out.

Like many others, however, I've been frustrated by the failure of the Chrome/Chromium developers to implement some very simple features that would greatly enhance the user experience. Despite scores of requests for them to implement bookmark tags, over several years, the response has been one of indifference. At times I've come very close to switching back to FF. It's funny how a feature you'd never had use for previously can become essential.

Funny thing is Google got it right with Google Bookmarks. They were ahead of the game. But now development on Bookmarks has all but ceased. Rather than adding functionality, they've stripped away support from it.

The bad news is that there doesn't appear to be any plan to implement bookmark tags in Chrome in the near future. The good news is that there's a simple workaround. It doesn't require installing an extension, and it syncs between computers. So here's how it works.

One of the really cool features of Chrome is the ability to create custom search engines for the omnibar. In fact, you can do just about anything with the omnibar, if you're willing to take the time to learn how. You can create a search engine for pretty much any website that's searchable.

How does this work? Well, you may have noticed that the url in the location bar (or omnibar in Chrome) changes when you search a website with your browser. Typically, your search query appears near the end of the url. I realize this is all pretty spoon-fed for the more tech-savvy among us, but bear with me.

If a website uses this type of search, you can create a custom search engine for Chrome by removing your search string from the url, and replacing it with %s. This symbol acts as a place holder for search queries. Sometimes you can create the search url quickly by just searching for "%s" on the website you want to create a search engine for.

Well, it turns out that you can also search your bookmarks this way. To get started, open your bookmark page with ctrl+shift+o and search for "%s". You should get something that looks like: chrome://bookmarks/?#q=%s. Now, right click in the omnibar and select "Edit Search Engines." Scroll down to the bottom and you'll see a row where you can "add a new search engine."

In the first box, just put whatever you want to call the new search engine, e.g. "Chrome Bookmarks." In the second box, you can set a keyword to activate the search engine. Whenever you type this keyword into the omnibar followed by a space, the search engine will be activated. Then you can type in whatever you want to search for in that website or, in this case, your Chrome bookmarks. In the last box, put the url, e.g. "chrome://bookmarks/?#q=%s." Now, press enter to save.

Pretty cool, huh? Note that you can also customize the keywords for the other search engines. I recommend something short and easy to remember. It should also be unique, so it doesn't get activated accidentally when you're googling something.

So now you can use the omnibar to search your bookmarks. But what about tags? Well, another great feature of search engines, known only to a geeky few, is called a wildcard character. There are different kinds of wildcard characters, which are all part of a larger concept known as "regular expressions," or regex. However, for our purposes, we're only concerned with the "*" wildcard character.

Of course, you probably recognize this term from card games like UNO or poker. Well, it works the same way. An "*" basically means "any number of random characters." So if I search for d*g, I might get results for anything from dog to daring. For more info on Google search operators, see this page.

Well, we can use this to set up a tagging system for our bookmarks. At the end of the bookmark title, put something like [tags:jobs, employment, ka-ching]. Just some way of saying, "Here are my tags." The key is to make it something that's very unlikely to show up in a regular bookmark title. Using my example, you would then modify your search url to look like this: chrome://bookmarks/?#q=[tags:*%s*]. Now, whenever you enter the search engine's keyword, e.g. "btag", you will be able to search for specific tags in your bookmarks.

Very simple. If you're like me, you don't like installing extensions for every little thing. And the best part is that it will sync between computers, if you have sync set up, because it's just part of the bookmark title. Of course, it's not nearly as slick as the implementation in Firefox. There's no autocomplete, and you can't browse by tag. But it offers a simple solution, if you want a way to tag your bookmarks, and are determined to use Chrome/Chromium.

At some point, I'd like to write an extension to make this work more like it does in FF. The good thing is that this method would allow for a fairly seamless transition to using the extension. A script could search through your bookmarks for the regular expression - e.g. [tags:*%s*] - and use it to create a tag index. And should the Chromium devs ever decide to implement tags, all your tagging efforts won't be lost. If you're really adventurous, you could always download the Chromium source code, and implement tagging into the browser itself. Oh, the wonders of open source! The only limit is your imagination.

Update (Sept. 1, 2013)

Well, I finally got tired of going without features that will probably never be implemented in Chrome, and having to open Firefox to view pages that Chrome still can't load. After reading a recent browser test in which Firefox handily out-performed Chrome, I decided to give it a try.

I'm impressed. Firefox has definitely made improvements since I switched over to Chrome a few years ago. While I have been using it several times a week to load pages that Chrome can't, it was never enough to see the difference.

It's so nice to have real tagging again, as well as some other powerful features. The only drawbacks I see are decreased integration with Google services, and a loss of simplicity in adding search providers. 

So I wrote a Python script to convert my Chrome tags into Firefox tags. You can download it here. If you use the same tagging syntax I describe above, it should work as is. Instructions are in the script. If you use a different syntax, you'll have to edit the 3 lines that start "tags = " and the regex match string.

Note that this script ignores case, which means that "Linux" and "linux" are treated as the same tag, and so on. If you don't want this, you'll have to edit a couple lines (tip look for "lower").

The normal caveats apply: Use at your own risk. Back up your bookmarks first. It worked perfectly for me. Unlike a lot of people, I don't post code that I haven't actually tested first. But there are no guarantees. As with any script you get off the internet, look through it before running it on your computer. I know I'm trustworthy but you don't. a simple line like "scp -r ~/.thunderbird myuser@myserver" could really ruin your week.

I adapted this script from one I found on a forum for converting tags. That may be useful to you, if you use that service. That script doesn't work as is, but I explained in my comment there what needs to be done to get it working.