Remotely add bookmarks to Firefox 2
At the office, I'm shelled into my laptop at home via ssh.
Sometimes I encounter an interesting link that I'd like to explore more
when I get home. "Social bookmarking" sites leave me cold, because it's
clear that sites like del.icio.us aren't about making my bookmarks portable
as they are about collecting cloud data. It's not a new problem, but I've
never liked the given solutions.
Here's a little shell program that I wrote, which lets me add a bookmark to my Firefox 2 Bookmarks Toolbar from my ssh session.
Before:
After:
I emphasize that it's for Firefox 2 because Firefox 3 supposedly uses SQLite for storing bookmarks. It will be much simpler to hit SQLite than this sed/HTML solution, but alas Gentoo has yet to bless us with a FF3 ebuild.
To use it:
- Save the following as bookmark.sh
chmod +x bookmark.sh- Configure two values in the script
./bookmark.sh CNN http://www.cnn.com
Enjoy!
# # This script will add a bookmark to Firefox 2. This is # useful, for example when remoting to the machine with # only ssh access. # The script works by finding an existing bookmark with the # name provided in PRIOR_LINK, and then prepending a new # link. Someone with better sed skills could eliminate the # PRIOR_LINK requirement. # # Two arguments are expected: The bookmark name and the full URL # # Some notes: # - This works with Firefox 2 only. FF3 will use SQLite to # store bookmarks # - This hasn't been tested much, so use reasonable inputs, # no unusual characters # - The script tries to use reasonable error-checking, but # I'M NOT LIABLE FOR ANY DAMAGE THAT MAY OCCUR, although # damage could be pretty easily repaired with a text editor. # # (c) Erik Mackdanz, free for any use # ######### ADJUST THESE VALUES!!! ########## # New links will go before the link with this name PRIOR_LINK=Gmail # Where is your bookmark file BM_DIR=/home/erik/.mozilla/firefox/31327a70.default ########################################### # What is your bookmark file's name FILE_PROD=$BM_DIR/bookmarks.html # What is a temp file we can use FILE_WORK=$BM_DIR/bookmarksWorking.html # Check inputs if( (($# != 2)) ) then echo "Usage: $0 name url" echo "Example: $0 GreatArticles http://mackdanz.net" echo "Relatively untested, so avoid special charcters like " or \" fi # In URL, replace / with \/ ESCAPED_URL=`echo $2 | sed -e "s/\//\\\\\//g"` #echo $ESCAPED_URL # A unique ID is needed ... use date as nanos RDF_ID=`date +"%N"` # The date parameters are hard-coded, but the effects are probably minimal NEW_LINK="
ID="rdf:\#\$$RDF_ID">$1<\/A>" # Insert new link into working bookmark file if ! sed -e "s/(^.*$PRIOR_LINK<\/A>$\)/$NEW_LINK /" $FILE_PROD > $FILE_WORK then echo Failure during text operation, quitting exit fi # Overwrite existing bookmarks file with working version if ! cp $FILE_WORK $FILE_PROD then echo Failure overwriting bookmarks file, quitting exit fi # Clean by deleting working version if ! rm $FILE_WORK then echo Failure deleting working file, quitting exit fi