Safari Bookmark management

This Mac OS X Hint is helping me learn more about bookmark management in Safari.[1] For example, here's a JS bookmarklet that searches for the selected text in Google, displaying the result in a new window:

javascript:x=escape(window.getSelection().getRangeAt(0));""+x, "_googTab");

I'm not sure about the easiest way to create a new bookmarklet in Safari's Bookmarks bar. So for now I just use the + button to add whatever web page I'm currently viewing; then click the Bookmarks icon, select the new bookmark, change its name, and replace its address w. the JavaScript for the bookmarklet.

Assigning Shortcuts

How do you assign shortcuts to bookmarks? Another hint shows how to do so without having to use the System Preferences => Keyboard and Mouse => Keyboard Shortcuts panel.

  $ defaults write NSUserKeyEquivalents '{"Google in New Tab"="@$G";}'

Opening in New Tabs?

Hm... So by using JavaScript bookmarklets, could I implement the 'Search in Google in New Tab' feature for which I've been pining?

Alas, it may be possible, but I don't know how to do it. Once I've put the bookmarklet in my bookmars bar, it doesn't matter whether I left-click or right-click and select "Open in New Tab"; I always get a new window. And if I change the JavaScript to set the current location rather than open a new window, then it always overwrites the current page.

It's too bad that (AFAIK) JavaScript does not yet recognize that many browsers support tabs.

[1]I've missed years of hints and from all over the web that show how to create search bookmarklets, for a host of search engines.) And of course Firefox has a much cooler keymarks facility, which Bob DuCharme explained way back in 2004.