Scripts to Apply & Sync a DEVONthink “Hook” tag — and More DEVONthink Goodies

Here are some potentially useful additional scripts for using Hookmark and DEVONthink together.

Synchronize “Hook” tag for DEVONthink items

Hookmark users have told us on the Hookmark Forum that it would be handy to be able to tell at a glance whether an item in DEVONthink 3 has a Hookmark link.

The script below does that.

-- remove "Hook" tag from every record item in DEVONthink
tell application id "DNtp"
    set recs to lookup records with tags {"Hook"}
    repeat with itemRec in recs
        set oldTags to tags of itemRec
        set newTags to {}
        repeat with t in oldTags
            set unwrappedTag to "" & t
            if unwrappedTag is not equal to "Hook" then
                set newTags to newTags & t
            end if
        end repeat
        set tags of itemRec to newTags
    end repeat
end tell

-- add "Hook" tag to every record item which has hooked links to other items
tell application "Hook"
    set addrs to address of (every bookmark whose address begins with "x-devonthink-item://" and hooked bookmarks is not equal to {})
end tell
tell application id "DNtp"
    set AppleScript's text item delimiters to "x-devonthink-item://"
    repeat with addr in addrs
        set itemID to text item 2 of addr
        delay 0.5
        set itemRec to (get record with uuid itemID)
        if itemRec exists then
            if tags of itemRec does not contain "Hook" then
                set tags of itemRec to tags of itemRec & "Hook"
            end if
        end if
    end repeat
end tell

Basically, this script goes through DEVONthink and removes the “Hook” tag from every item (in case there are tagged items which don’t have links anymore) and then it goes through Hookmark and finds every DEVONthink bookmark with linked items and adds a “Hook” tag to it in DEVONthink.

This just adds a tag. It doesn’t affect the icon or add any visual affordance, but maybe there’s some way for users to do that themselves for items with a given tag.

This is meant to be scheduled to run regularly, in launchd or whatever service user prefers.

More information about Hookmark integration with DEVONthink

Additional integration scripts are accessible from: