Fraser Speirs ([info]fraserspeirs) wrote,
@ 2005-06-03 08:28:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Del.icio.us Script
So I got my script for posting to Del.icio.us going. Instead of a bookmarklet, I wrote an Applescript that I can fire from Quicksilver. Thanks to Buzz for the pointers.

So we use Applescript to pull out the URL, then Javascript invoked from Applescript to get the document title. Then we compose the URL and call out to Curl to do the transport and then, of course, we talk to Growl for reporting the success or otherwise of the submission. Love it.

tell application "Safari"
  set username to "xxxxx"
  set mypasssword to "xxxxx"
  
  set theURL to URL of front document
  set theTitle to do JavaScript "escape(document.title)" in front document
  
  set theDelURL to "http://" & username & ":" & mypasssword & "@del.icio.us/api/posts/add?url=" ¬
          & theURL & "&description=" & theTitle & "&tags=@review"
  
  set theresult to do shell script "/usr/bin/curl -s \"" & theDelURL & "\""
  
  tell application "GrowlHelperApp"
    -- Perform some Growl housekeeping tasks to register ourselves.
    set the allNotificationsList to {"Submit Result"}
    set the enabledNotificationsList to {"Submit Result"}
    
    register as application ¬
      "@Review Script" all notifications allNotificationsList ¬
      default notifications enabledNotificationsList

    if theresult contains "done" then
      -- Talk to Growl
      notify with name ¬
        "Submit Result" title theTitle¬
          description "Successfully Submitted" application name "@Review Script"
    else
      notify with name ¬
        "Submit Result" title theTitle ¬
          description "Submission Failed!" application name "@Review Script"
    end if
  end tell
end tell



(Post a new comment)


[info]spike
2005-06-03 11:41 am UTC (link)
This is a fabulous example of what I call a "glue job" -- most of the code is just gluing existing pieces together in a new way. Gluejobs are my absolute favorite kinds of code, and AppleScript makes it all just sing.

Kudos!!

(Reply to this) (Thread)


[info]fraserspeirs
2005-06-03 06:47 pm UTC (link)
Thanks! I'm really pleased with this script :-)

(Reply to this) (Parent)

Excellent
(Anonymous)
2005-06-03 04:03 pm UTC (link)
Wow. Excellent solution. I'm using it already. Now if I can just have a way to automate the summation of articles I tag with @review at the end of the day and have it emailed to me.

Cheers!

Tim

(Reply to this)

Keychain Integration
[info]celkins
2005-06-04 02:29 am UTC (link)

Very nice!

If you want to retrieve the username and password from the keychain rather than hard-code it in the script, you can add something like the following:

tell application "Keychain Scripting"
    set theKey to first key of current keychain whose name is "del.icio.us"
    set username to account of theKey
    set mypasssword to password of theKey
end tell

The above assumes the presence of a keychain item named "del.icio.us" where the account field contains your username. (I'm piggybacking on the one added by Cocoalicious.)

Additionally, you'll need to launch "/System/Library/ScriptingAdditions/Keychain Scripting.app" beforehand (in Tiger) and allow it and "/System/Library/CoreServices/System Events.app" access to the keychain item (to work around security dialogs that for some unknown reason don't allow access even if you choose the appropriate button).

(Reply to this)


[info]deus_x
2005-12-31 12:06 am UTC (link)
Cool hack, though I'm curious: Why use this instead of a bookmarklet? Because you can?

Also: Do you mind if I mention you and this in my book?

(Reply to this) (Thread)


[info]fraserspeirs
2005-12-31 10:15 am UTC (link)
Why use this instead of a bookmarklet? Because you can?

I have the bookmarklet in my browser for the times I just want to post a link. This script is just a quick way to post links with the single tag "@Review":

- Because I can fire it from Quicksilver
- So I don't have to edit the del.icio.us form to fill in the "@Review" tag every time

Do you mind if I mention you and this in my book?

Please do, and good luck with the book. Could you link to http://speirs.org/hacks/ rather than to this post?

(Reply to this) (Parent)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…