Converting .webloc files

Speech of the day: Aragorn’s ever-popular not this day monologue

Warning: Geeking ahead!

Safari and most other Mac browsers will save individual links as a clickable .webloc file, recognizable by the little “HTTP” on the document icon. I’m always dragging links from Safari or Mail to the desktop for later reading, blogging, or filing away. When I’m off-line and I just want to click something later, a webloc is fine, but when I have a huge folder full of links, reopening each one in Safari can be a pain. Cutting and pasting links for a link dump blog entry is time-consuming. There ought to be a script for that, so I wrote one.

Webloc files are hard to work with because the URL is in the resource fork. Here are a few useful links that discuss getting the URLs out of the resource fork—incidentally, this link dump is an example of my new script in action:

The case I really wanted to handle was my collection of reference links. Normal people would bookmark them but I keep them in folders sorted by topic, along with html and other files. I’ve tried wikis and blogs and xml DTDs for keeping information organized, but I’ve found that the best knowledge management software for me is the Apache webserver that came with my mac. Safari will display xml, text, html, pdf, and rtf, plus my local WordPress writing journal, so I keep all my writing info on my local website. I use a php script to index each directory and provide navigation. The system works perfectly, except that I can’t see the .webloc files or open them through Apache—they can only be opened by clicking on them in the Finder.

So I took a shell script from one of the macosxhints articles about converting Mac weblocs to the PC analogue, and hacked it until it took a bunch of weblocs and converted them to an html list, which can be easily cut and pasted into the blog. The output is actually a full html page (sent to stout) which I can use for my local web pages. The script can be edited easily to change the html. At some point I may make a version that outputs markdown-native links.

To use the script, download linkdumper.txt. Change the permissions so it’s executable (chmod 755 linkdumper.txt), rename it if you’d like, then run it in the Terminal. Typing ./linkdumper.txt *.webloc should work, if you don’t understand shell scripts. If you type just ./linkdumper.txt, you get a short help blurb. I keep my copy of the script in ~/Library/Scripts/, though I had to add that directory to my path. Please keep in mind that I know very little about shell scripting, and weird things may happen. Weird things happened during the hacking of this script, though I’ve been unable to reproduce them.

Pardon the extreme geeking.

P.S. I forgot to link Faviconic, a nice little program to add a site’s favicon to its webloc icon.

Comments are closed.