Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Grab all bookmarks for your account, create a bookmark file for Launchbar indexing
This script is designed to generate a simple html file with _all_ of your bookmarks
The HTML file can be added to Launchbar's index as a custom bookmark file and you can search
your entire collection instantly from Launchbar (by title only). It includes
any applied tags as part of the title to aid in searching.
This does no checking for deltas, it just grabs the whole bunch and overwrites the html file
every time. Don't run it too frequently.
Set your username, password and the path/filename to write to below.
### User configuration
PB_USERNAME = 'username'
PB_PASSWORD = 'password'
BOOKMARK_FILE = 'path/to/store/PinboardBookmarks.html'
### END config
require 'cgi'
require 'fileutils'
require 'net/https'
require 'rexml/document'
class Net::HTTP
alias_method :old_initialize, :initialize
def initialize(*args)
@ssl_context =
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
def get_bookmarks
xml = ''
http ='', 443)
http.use_ssl = true
http.start do |http|
request ='/v1/posts/all')
request.basic_auth PB_USERNAME,PB_PASSWORD
response = http.request(request)
xml = response.body
def bookmarks_to_array(doc)
bookmarks = []
doc.elements.each('posts/post') do |ele|
post = {}
ele.attributes.each {|key,val|
post[key] = val;
return bookmarks
bookmarks = bookmarks_to_array(get_bookmarks)
output = ""
bookmarks.each do |b|
output += %Q{<a href="#{b['href']}" title="#{CGI.escapeHTML(b['extended']).gsub(/\n/,' ')}">#{b['description'].gsub(/\n+/,"\n")} @#{b['tag'].split(' ').join(' @')}</a>\n}
# Append to a file:
open(File.expand_path(BOOKMARK_FILE), 'w') { |f|
f.puts output
Copy link

dlo commented Jan 24, 2013

If you'd like to use the OS X keychain to prompt for your password (and having writing your password in plain text in here), replace line 15 with something like this:

PB_PASSWORD = `security find-internet-password -s -w | tr -d '\n'`

Copy link

dlo commented Jan 24, 2013

Forked and wrote a Python version that pulls all bookmarks on the first sync, and does incremental updates afterwards. Also uses the Mac OS X keychain to retrieve your password so it doesn't need to live in a file on your computer in plain text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment