A Pretty Good Script for Creating a Yojimbo Bookmark From Safari, With Tags, Comments, and Growl Support

Up until last month I had always just used the “Archive to Yojimbo” and “Bookmark to Yojimbo” javascript bookmarklets which the Bare Bones team provides. Saved as triggers that I launched through Quicksilver, I had been getting on fine with them for quite some time.

But after my switch to FastScripts instead of Quicksilver it seemed a good time to finally write my own, ideal script for crating a Yojimbo bookmark. Though a slew of AppleScripts out there already do this, none of them work quite the way I wanted.

Since I never know what words I’ll use when searching for some long lost bit of info in Yojimbo, I’ve found that the more metadata I can give an item when it’s created the easier it will be to find it some day. Which is why, in addition to tags, I wanted a ridiculously simple way to get a portion of text from the Web page into Yojimbo’s Comments box when creating a new bookmark.

The easiest way to do this is to take a highlighted chunk of text from the Web page and tell the script throw it into the new bookmark item as a comment. And that is precisely what this script does.

When invoked, the script takes the frontmost tab in Safari and creates a new bookmark item in Yojimbo. You’ll be given the opportunity to enter any tags before the bookmark is created, and if you’ve selected any text from the Web page you’re bookmarking it will get pasted into the Comments box of your new Yojimbo bookmark. Finally, once the script has successfully run, a Growl notification will let you know.

Additional cleverness comes to play in the case that your URL is already bookmarked in Yojimbo. If so, a dialog box will let you add the URL again or open Yojimbo and edit the pre-bookmarked item. Or you can simply cancel and pretend like you knew all along that you’d already bookmarked that page. (This bit of functionality is based heavily on another bookmark in Yojimbo script written by Jim DeVona.)

The section of the script that prompts for tags is based on a script by John Gruber. His original code looks like this:

set _tags to {}
try
    display dialog "Tags:" default answer ""
    set _answer to text returned of result
    if _answer is not "" then
        set AppleScript's text item delimiters to ", "
        set _tags to text items of _answer
    end if
end try

It’s short and clever, but once you run it you’re committed. Sometimes I invoke the script and, for whatever reason, I change my mind. But with the above code, hitting the “Cancel” button doesn’t quit out of the script — rather it just continues on without generating any tags and the bookmark is still created.

And so I modified John’s tag input code to bail if you hit Escape or click “Cancel”. To bookmark an item with no tags just leave the input field empty and press Return or click “OK”.

set _tags to {}
set _dlog2 to display dialog "Set tags (if any):" default answer ¬
    "" default button 2 cancel button 1
set _action2 to the button returned of _dlog2
if _action2 = "" or _action2 = "Cancel" then
    return
else
    set _answer to text returned of _dlog2
    if _answer is not "" then
        set AppleScript's text item delimiters to ", "
        set _tags to text items of _answer
    end if
end if

Download

Updated on March 20, 2012:

  • Zachery Jensen updated the script so that it now properly takes the selected text from your current Safari window and places it as a comment in the Yojimbo bookmark.
  • The `tell` command which previously referenced “GrowlHelperApp” now references “Growl” in order to support the Mac App Store version of the app.

P.S. Mail To Yojimbo script updated also

The MailToYojimbo script is updated as well with the improved Tag support (added October 2009) and fixes for the new Growl (added March 2012).

Publishing this site is my full-time job. If you enjoyed this article, please consider supporting the site by becoming a member. There are some great perks.