thank you for providing such a great venue for all kinds of scripts and thanks to the authors for providing such a great program. I have now been customizing DT for two weeks, but could not make the following work:
I would very much like to post items via my DT to delicious, preferably via an internal DT window. I could not get this work, and have it now via my browser via the following code (modified from another script - thanks!!)
-- NetNewsWire to Del.icio.us
--
-- Grabs info from current browser window in NetNewsWire
-- and posts it to your Del.icio.us account
--
-- Change YOUR_ACCT_NAME below to your own info
--
-- Based on work by "JCHRIS":
-- http://dtrl.blogspot.com/2005/03/net-news-wire-20-delicious-apple.html
--
-- Modified by Daniel Jalkut to base source URL on selected tab, so it will
-- work for both subscriptions and web URLs. Latest version available here:
--
-- http://www.red-sweater.com/AppleScript/
--
-- Red Sweater Version 1.0
set theAccountName to "xxx"
tell application id "com.devon-technologies.thinkpro2" to set thisSelection to the selection
if thisSelection is {} then error localized string "Please select a document or group, the try again."
if (length of thisSelection) > 1 then error localized string "Please select only one document or group, then try again."
tell application id "com.devon-technologies.thinkpro2"
set thisItem to first item of thisSelection
set theTitle to (name of thisItem) as string
set theURL to (URL of thisItem) as string
end tell
if (theURL is not equal to "") then
set deliciousURL to "http://del.icio.us/new/" & theAccountName & "?v=2&url=" & theURL & "&title=" & theTitle & "&tags=" & theUUID
tell application "System Events"
open location deliciousURL
end if
I would like to fetch the tags (i.e. the file location maps displayed as tags like “Politics” “International Relations” “Afghanistan” “Uruzgan”) to delicious tags and secondly have the window displayed inside DT as opposed to in a browser window.
Thank you so much for any help you can offer. It is highly appreciated!
Here’s a script that should work, although the tags aren’t transmitted for some unknown reason:
-- Post to del.icio.us
property pAccountName : "" -- Set your account name here
tell application id "com.devon-technologies.thinkpro2"
try
set thisSelection to the selection
if thisSelection is {} then error localized string "No selection."
set theWindow to think window 1
repeat with thisItem in thisSelection
set theURL to URL of thisItem
if theURL is not missing value and theURL is not "" then
set theTitle to name of thisItem
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "} -- Tags separated by spaces
set theTags to (tags of thisItem) as string
set AppleScript's text item delimiters to od
set theURL to do JavaScript "encodeURIComponent('" & theURL & "')" in theWindow
set theTitle to do JavaScript "encodeURIComponent('" & theTitle & "')" in theWindow
set theTags to do JavaScript "encodeURIComponent('" & theTags & "')" in theWindow
set deliciousURL to "http://del.icio.us/new/" & pAccountName & "?v=2&url=" & theURL & "&title=" & theTitle & "&tags=" & theTags
open tab for URL deliciousURL in theWindow
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
I wondering if this might be a bug relating to how DT internally exposes the tags to AppleScript…
For what it’s worth, a user of my DEVONthink-to-Evernote AppleScript posted a comment this morning that the script wasn’t working now. When I stepped through the script with my editor, the script halted every time I called the tags of a DEVONthink item.
The tag variable was showing as «empty», so I thought maybe I could do a missing value check to insert a default tag in the transfer for untagged items. No luck – the script halts whenever it hits an untagged item.
Am I missing some (probably obvious) way to deal with this?
No, it’s not related to AppleScript. I’ve also entered some URLs on my own in a browser window but without luck, the tags aren’t accepted by del.icio.us.
Just send me the script plus some sample data and I’ll check this.
The sample data will obviously be from your own DEVONthink Pro database, but let me tell you what I noticed as I was working with my own data and also stepping through the script line-by-line with Script Debugger:
DEVONthink Pro notes with tagsexported correctly to Evernote, and Script Debugger was able to read the values for the tags (e.g., everything works as expected);
DEVONthink Pro notes without tagscaused the error and, when I stepped through the script line-by-line with Script Debugger, that’s when I saw that 1.) The script halted directly after trying to retrieve the (non-existant) tags, and 2.) the debugger showed the tag variable was «empty» ;
Let me know if you have any questions – and thanks for trying to get to the bottom of this!