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.

This entry was posted in neep-neep. Bookmark the permalink.

4 Responses to i shot an arrow into the air

  1. Anton says:

    I could try putting a random bookmark server on this here site. I’d need to mark NSFW matter somehow.

  2. Anton says:

    Speaking of NSFW, just now it chose a link to a dead domain, which redirects to a hardcore pr0n site. Unfortunately the redirect means I can’t tell which bookmark to delete.

  3. Anton says:

    So now the program logs the address that it attempts to open.

  4. Anton says:

    Now instead of going through the shell “open” command I use webbrowser.open_new_tab(), which doesn’t need the replacement of “&”.

Leave a Reply

Your email address will not be published. Required fields are marked *