How do triggered scripts work? (it seems like they don't)

I’ve got the simplest of scripts possible:

on triggered(the_record)
	tell application id "DNtp"
		display alert "funky"
	end tell
end triggered

I’ve attached it to a DT group, and it shows the little script icon. But when I click the group… nothing happens.

The DEVONthink documentation says to look at an “extras” folder in the DEVONthink disk image for examples. But there’s no extras folder… so I dug around the forums and found this “on triggered()” approach.

But DEVONthink doesn’t display an alert. And it definitely doesn’t run any of the other code that I tried.

So – how do you make triggered scripts work?

What version and OS are you running?
I took your code as is, saved it as a script, attached it and it worked as expected.

Also, just for due diligence, have you rebooted lately?

Also works fine over here – 10.11.4 and DTPO 2.8.10.

Ah okay, it seems to be a slightly different problem than I thought. DEVONthink appears to be caching the script. So my first version of the script was incorrect (I didn’t have the on triggered). But changing and saving the script didn’t do anything… even if I cleared out the triggered script.

Guess you gotta restart DEVONthink to reload the script.

Ah, yes. Now you say that, I recall the caching and the need to force an update by restarting DEVONthink.

The same issue can affect Toolbar scripts – custom scripts that can be placed on any toolbar (not just the main toolbar). These do not require a specific wrapper, like triggered scripts. Toolbar scripts have to be located in ~/Library/Application Support/DEVONthink Pro 2/Scripts/Toolbar. To put them on a toolbar, use View > Customize Toolbar…, and you’ll find your Toolbar scripts at the bottom of the “drag your favorite items into the toolbar…” pane.

While the Toolbar folder is required, for triggered scripts there is not a required location for the scripts, but I find it useful to put triggered scripts into a personal folder I created at ~/Library/Application Support/DEVONthink Pro 2/Scripts/Triggered

Triggered Scripts, and Toolbar scripts, are powerful features of DEVONthink that I suspect most readers never encounter. Half of my personal toolbar comprises commands I wrote myself to do important things specific to my work and document management. Don’t forget that triggered scripts can even be assigned to individual documents – e.g., to update a table that’s stored in that document. (There was a long thread here on that subject in the past few years.)

@padillac, if you’re inclined, would you mind sharing what you’re doing with your triggered script(s)? It can be illustrative for other readers.

Nothing too fancy… in fact, I’m pretty sure this is the first triggered script I’ve used in 6 years of DEVONthink usage :slight_smile: I have written a handful of scripts that I use regularly though, and today I got tired of running this particular one manually.

It’s a modified version of the “Rename -> Replace Text” script that comes with DEVONthink. I just hard-coded a few strings that I want to get rid of. It’s attached to one of my database’s inbox, so any time I select the inbox it just cleans up the names for me.

on triggered(the_record)
	tell application id "DNtp"
		set searchStrings to {" : rails", " : ruby", " - Ruby Forum"}
		
		set theRecords to children of the_record
		
		set od to AppleScript's text item delimiters
		
		repeat with the_record in theRecords
			set current_name to name of the_record
			
			repeat with search_string in searchStrings
				if current_name contains search_string then
					set AppleScript's text item delimiters to search_string
					set text_item_list to every text item of current_name
					set AppleScript's text item delimiters to " "
					set new_item_name to text_item_list as string
					set the name of the_record to new_item_name
				end if
			end repeat
			
			set tags of the_record to (parents of the_record) & "extract keywords"
		end repeat
		
		set AppleScript's text item delimiters to od
	end tell
end triggered

I do see a lot of potential power in triggered scripts though… so I think it’s mostly a matter of documenting my workflow to see how I would script it out.

I can certainly imagine just clicking down a list of smart groups and having documents move from one to the next automatically based on decisions I encode in scripts… but that’s all pretty far away at this point I think :slight_smile:

That’s a good use of triggered scripts in the Global Inbox or other database Inbox.