DEVONthink and Trickster integration

@Jacob, thanks for the reply!

It’s working now. After I wrote, the system finally asked permission to grant access / control between DT and Trickster. I don’t know why it didn’t do it immediately, or even after several attempts at it. In any case, it’s working now.

(Similarly, only this morning did it ask to grant Trickster access to Photos. I didn’t do anything other than restart my laptop.)

I do have a follow up question.

It seems that Trickster only works on files opened by DEVONthink, whether that’s with DT’s file viewer or its preview pane. Correct?

However, many of my files are indexed, and I have the default action to open them in the default external app. When I open such a file (eg, DT opens an .rtf file with TextEdit), Trickster does not recognize this as opened, neither by DEVONthink nor TextEdit.

I would think one or the other (if not both) would register in Trickster. Is there a way to do so?

Hi, thank you for bring this issue to my attention. I’ve looked at this and have a partial solution but it also looks that there’s a bug in DEVONthink for full support of this.

First of all, it look like opening the document externally from DT indeed doesn’t register in Trickster. My guess is that the approach DT uses to launch an external application may not be registering on the OS level and thus the information doesn’t arrive to Trickster either.

Now, on DEVONthink level itself, you can modify the Smart Rule condition to also fire when “Open Externally” condition is met like in the screenshot below. I tried this but it only seems to work when opening in an external tool using “Open With” in the context menu, not when the document is opened by an external tool by double-clicking on it, when that option is enabled in DT’s preferences, like in your case. This latter behaviour (not running the Smart Rule when double-clicking) I would consider a bug in DEVONthink since I’d expect “On Open Externally” to fire regardless if I double-clicked on a file to open externally or used “Open With”. Please contact DEVONthink’s support about this, if this is important.

It may make sense for me to update the Smart Rule to include “On Open Externally” by default but until this bug is fixed in DT, it will be of limited use.

@Jacob, thanks.

I see the same behavior on my end. Hm.

I’ll report it to DT, both directly and on this related thread, in case you want to chime in or follow along.

1 Like

Thanks Jacob, I really appreciate your customer support. I didn’t think about Hook, but now use it along the lines you suggested. DNT + Trickster + Hook is awesome.

1 Like

This does indeed work well with Hook - thanks

1 Like

A kind of a temporary workaround
Bind it a key

BTW, @Jacob, a strange behavior of add recent function… If you remove a delay in this script - all goes without an error, but recent item is not added…

The script is quick, and if it is possible to remove the delay, then one can create a smart rule for “on open” event for the Group using this script.

-- Script to add selected DT Group to Trickster's Recents
-- Created by Silverstone on 12.07.2021

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set theRecords to (get selection)
	if (count of theRecords) = 1 then
		
		-- Data for recent item
		set theRecord to item 1 of (get selection)
		set {GroupURL, GroupName, GroupLocation} to {reference URL, name, location} of the theRecord
		set AppName to name
		
		-- Finding or creating 'Group Links' DT group in Inbox of current database to store all link files
		set theFound to search "name==Group Links kind:group" in the incoming group of current database
		if (count of theFound) is 0 then
			set theGroupLinks to create record with {name:"Group Links", type:group} in the incoming group of current database
		else
			set theGroupLinks to item 1 of theFound
		end if
		
		-- Finding or creating the bookmark
		set theFound to search "name==" & GroupName & " url==" & GroupURL & " kind:bookmark" in theGroupLinks
		if (count of theFound) is 0 then
			set theLink to create record with {name:GroupName, URL:GroupURL, type:bookmark} in theGroupLinks
			delay 3
		else
			set theLink to item 1 of theFound
		end if
		set thePath to path of theLink
		
		-- Creating the recent item in Trickster
		tell application "Trickster" to add recent thePath source AppName displayPath GroupLocation callbackURL GroupURL bundleID "com.devon-technologies.think3"
	else
		display dialog "Choose a Group" buttons {"OK"} default button "OK"
	end if
end tell
2 Likes

DEVONthink says they will fix this double-click issue in their next release.

OMG, this is an amazing solution - creating and saving the link in DEVONthink itself. You’re much knowledgable about AppleScript (and obviously DEVONthink) than I am.

I’ve copied this into the Script Editor and saved it as a file. Here’s the download:

Screen Shot 2021-07-12 at 17.48.10

I then looked for a quick way to use it and I noticed that the Scripts Folder of DEVONthink has a Toolbar menu. So I copied the script file there and after restaring DEVONthink, I right-clicked on the toolbar, selected Customize Toolbar, and dragged the script from there to the real toolbar:

Now I can select a group and click that icon in the toolbar to run this script and see it in Trickster. :exploding_head:

Here’s a modified version of the original integration script (courtesy of @DEVONtech_Jim, which I just restyled) which also shows the database name in Trickster, in start of the path. I chose to show the database name in like [database] but you can edit the script to restyle it. Download by clicking on the link.

Screen Shot 2021-07-12 at 17.45.57

Here’s what it looks like in Trickster:
Screen Shot 2021-07-12 at 17.46.44

If you use this script, delete or disable the other one, since they do the same thing just a bit differently.

2 Likes

Outstanding solution - huge thanks

This is appreciated, I use it everyday

I could do a better integration, but function add recent is buggy. It requires about 3 second of delay before it can do something.

I don’t think that add recent is buggy. In the other scripts, add recent doesn’t require a delay. But add recent command does require an existing path and thePath in your script is dependent on DT’s creating the link file in its database folder. Your script delays when it creates a new link file but not when an existing one is found. So I think the delay comes from DEVONthink’s implementation of creating the new record.

It may be as well. I tried to make a wait block with ‘exist’ command - no luck. I guess I need to be more specific about disk write timing…

But, from the other hand, I set thePath variable before the ‘add recent’ function and it gets the right value

Anyway, if the function does not add the recent item for this or that reason - it should generate a human readable error

1 Like

@Jacob, I made some tests and tend to think that the problem is not in Devonthink. After DT creates a new bookmark, I get its path and check with a shell script do shell script "test -f " & quoted form of thePath. It shows that the bookmark file exists on the disk before script runs add recent function, as well as other input data. So, the problem is somewhere in this function and/or Trickster.

@Silverstone I’ll take a look at that and check what happens on Trickster side when there’s no delay.

This smart rule appeared in the Extras section in DEVONthink a couple days ago. Is it any different than the original one posted last week?

Yes, DEVONthink updated the script to the newer one that I’ve posted in the bottom of the original post of this thread. It’s the script that also shows the database name in Trickster. Otherwise, it’s the same functionality.

1 Like

Little update to the smart rule script:

  • added “?reveal=1” to the ItemLink to reveal the item instead of opening it in a new window
  • added condition not to include DT groups.

The second one is for opening groups in DT. If you try to open group without it, Trickster will generate error trying to add recent with non-existent path (you can see this error in DT log window).

It is also useful for those who turned on a hidden DT pref DisplayGroupsInPreviewPane to create open events for groups (you can then create a Smart Group with a date opened condition to see the history of opened groups) in DT.

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			if kind of theRecord is not "group" then
				set itemLink to the (reference URL of the theRecord) & "?reveal=1"
				set thePath to the path of the theRecord
				set {recDB, recLoc} to the {name of database, location} of theRecord
				set recordPath to ("[" & recDB & "]" & recLoc) as string
				set appname to name
				tell application "Trickster"
					add recent thePath source appname displayPath recordPath callbackURL itemLink bundleID "com.devon-technologies.think3"
				end tell
			end if
		end repeat
	end tell
end performSmartRule

I recommend to save compiled script in ~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules and choose external script in smart rule.

Don’t forget to restart DT after saving the smart rule.
Enjoy!

Hi,
I’ve just installed Trickster - buying Setapp to be able to use your excellent product to improve my DT3 workflow.
I set it up as per your video, but when I open a document through DT3, and then double click on trickster, all that happens is the DT3 icon appears in the recent window: the file itself is not opened.
I tried all the steps in your reply above but could not understand your bullet point 3 about topmost “All Files filter”.
Trickster is installed in the /applications/setapp folder - I moved it to /applications but this made no difference
I uninstalled shut down and restated my MacBook then reinstalled, but no luck.
I’m running MacOS 12.2 (21D49)
help?
Joe