Del.icio.us

Here’s an avdanced script to import bookmarks from del.icio.us. This script tries to use the keychain and if the keychain does not contain a key for del.icio.us and if the user/password properties are undefined, then dialogs pop up to enter the appropriate information.

In addition, the tags of each bookmark are added to the comments of the imported items and therefore you can easily search for them.

Please let me know if it’s working for you - thank you!


-- Import del.icio.us bookmarks
-- Created by Christian Grunenberg on Mon Jan 23 2006.
-- Copyright (c) 2006. All rights reserved.

property pUser : ""
property pPassword : ""

tell application "DEVONthink Pro"
	try
		set theURLs to {}
		set theNames to {}
		set theTags to {}
		
		if (pUser is "") or (pPassword is "") then
			try
				tell application "Keychain Scripting"
					set theKey to first Internet key of current keychain whose name is "del.icio.us"
					set pUser to account of theKey
					set pPassword to password of theKey
				end tell
			end try
		end if
		
		if pUser is "" then
			repeat
				display dialog "Enter username:" default answer "" buttons {"Cancel", "OK"} default button 2
				set pUser to the text returned of the result
				if pUser is not "" then exit repeat
			end repeat
		end if
		
		if pPassword is "" then
			repeat
				display dialog "Enter password:" default answer "" buttons {"Cancel", "OK"} default button 2
				set pPassword to the text returned of the result
				if pPassword is not "" then exit repeat
			end repeat
		end if
		
		set theXML to download markup from "http://del.icio.us/api/posts/all" user pUser password pPassword encoding "UTF-8"
		
		if theXML is not "" then
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "href=\""}
			set theHrefs to text items 2 thru -1 of theXML
			set AppleScript's text item delimiters to "\""
			repeat with theHref in theHrefs
				set theURLs to theURLs & (text item 1 of theHref)
			end repeat
			
			set AppleScript's text item delimiters to "description=\""
			set theDescriptions to text items 2 thru -1 of theXML
			set AppleScript's text item delimiters to "\""
			repeat with theDescription in theDescriptions
				set theNames to theNames & (text item 1 of theDescription)
				if theDescription contains "tag=\"" then
					set AppleScript's text item delimiters to "tag=\""
					set theTag to text item 2 of theDescription
					set AppleScript's text item delimiters to "\""
					set theTags to theTags & (text item 1 of theTag)
				else
					set theTags to theTags & ""
				end if
			end repeat
			set AppleScript's text item delimiters to od
			
			if (count of theURLs) is equal to (count of theNames) then
				set theGroup to create location "del.icio.us"
				set theCnt to (count of theURLs)
				repeat with i from 1 to theCnt
					set theURL to (item i of theURLs)
					set theName to (item i of theNames)
					set theTag to (item i of theTags)
					if not (exists record with URL theURL in theGroup) then
						create record with {name:theName, type:link, URL:theURL, comment:theTag} in theGroup
					end if
				end repeat
			else
				error "Unknown error."
			end if
		else
			error "Download failed."
		end if
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "DEVONtink Pro" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

Hi, excellent: would be nice if I can restrict that import to certain combinations of keywords.

Thanks Thomas