Monday, 2005 November 7, 12:00 — neep-neep

i shot an arrow into the air

My bookmarks file has 4539 entries, most of which I intend to look at “someday”. So I’ve written a little utility (two lines of code, plus scaffolding) that other Unix users may find useful, provided that your favorite browser keeps bookmarks in a textfile (as the Mozilla family does). Once an hour it picks a bookmark at random and opens it in my default browser. My crontab contains this entry:

01 * * * * sh ~anton/bin/bookcron

meaning: at :01 of every hour, run the following shell script:

cd ~anton
cat Library/App*/Firefox/Profiles/*/bookmarks.html | grep -o “http[^\”]*” | python bcp

which extracts any links from any bookmarks files and feeds them to this Python program:

import os
import sys
import random
os.system(“open %s” % random.choice(sys.stdin.readlines()).replace(‘&’,’\\&’) )

The function random.choice picks a random entry from the list. The command open does the right thing on MacOS X, but for other Unices you’ll probably need to replace it with the browser name. The replace() prevents silly things that would otherwise happen when a shell command contains an ampersand.

Subscribe without commenting

RSS feed for comments on this post.

Leave a comment