Integration with Hook

I’ve started to look at Hook, which might fulfill a need which I think I might have :thinking: One obvious problem with Hooking from DT is that I can’t see that an item has a hook without actually looking for one.

This post on the Hook forum suggests that a dynamic lookup and integration of an appropriate icon would probably be a doddle.

I am aware of the script on offer which tags hooked items in DT; that’s an adequate solution, but not as clean & nice as proper integration. So I’d like to request integration of Hook (that is an icon showing an item has a hook). Thanks for considering :slight_smile:

2 Likes

Here’s a revision of Luc’s script (see https://hookproductivity.com/help/integration/using-hook-with-devonthink/devonthink-hook-applescript/) which supports all databases, is faster and adds error handling:

property pTag : "Hook"

tell application id "DNtp"
	tell application "Hook" to set hookedLinks to address of (every bookmark whose address begins with "x-devonthink-item://" and hooked bookmarks is not equal to {})
	try
		repeat with theDatabase in databases
			repeat with taggedRec in (lookup records with tags {pTag} in theDatabase)
				set oldTags to tags of taggedRec
				set newTags to {}
				repeat with t in oldTags
					if (t as string) is not equal to pTag then set newTags to newTags & t
				end repeat
				set tags of taggedRec to newTags
			end repeat
		end repeat
		
		set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "x-devonthink-item://"}
		repeat with l in hookedLinks
			set theRecord to get record with uuid (text item 2 of l)
			if theRecord exists then set tags of theRecord to tags of theRecord & pTag
		end repeat
		set AppleScript's text item delimiters to od
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

But better (meaning automatic and more efficient) is probably to use a scheduled smart rule like this one…

…and the following script:

-- The (scheduled) smart rule has to find items already tagged with "Hook" and to untag them as this scripts adds only the tag

property pTag : "Hook"

on performSmartRule(theRecords)
	tell application "Hook" to set hookedLinks to address of (every bookmark whose address begins with "x-devonthink-item://" and hooked bookmarks is not equal to {})
	tell application id "DNtp"
		try
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "x-devonthink-item://"}
			repeat with l in hookedLinks
				set theRecord to get record with uuid (text item 2 of l)
				if theRecord exists then set tags of theRecord to tags of theRecord & pTag
			end repeat
			set AppleScript's text item delimiters to od
		end try
	end tell
end performSmartRule
3 Likes

BTW:
The smart rule can be also used to easily view all currently hooked items.

That is wonderfully fast and clean, thanks :slight_smile: I haven’t used flagging in the past, so I’ve added a flag to the smart rule and script - so now the records have an optical mark too. Nice - thanks Criss!

PS looking through the forum there have been a couple of requests for coloured flags. Whilst I don’t need coloured flags, if’d be nice to be able to define the colour of the single flag which is available in DT - that way it would be easier to make it stand out from the mass of locked items :slight_smile: So that’s my feature request now (I know, some ppl just don’t get enough :crazy_face: or can I do that myself some way -> didn’t find anything in the forum, so I guess not).

1 Like

Since version 3.7.2 this script can be simplified a little bit:

property pTag : "Hook"

on performSmartRule(theRecords)
	tell application "Hook" to set hookedLinks to address of (every bookmark whose address begins with "x-devonthink-item://" and hooked bookmarks is not equal to {})
	tell application id "DNtp"
		try
			repeat with l in hookedLinks
				set theRecord to get record with uuid l
				if theRecord exists then set tags of theRecord to tags of theRecord & pTag
			end repeat
		end try
	end tell
end performSmartRule
2 Likes