Smart Rule If open Group XYZ → automatically select Table of Contents Document

Hello,
In terms of Workflow, I notice that when I open certain groups, I systematically go to the Document whose name contains Table of Contents.
I tried and failed to create a Smart Rule which would make this process automatic (ie automatically select the Document whose name contains Table of Contents.
thanks in advance for your time and help

Smart rules don’t support such actions, the only possibility would be a custom script.

1 Like

thank you Christian

This triggered script selects the first child record whose name contains “Table of Contents”.

I would use something that can be altered via UI as on/off toogle, e.g. the record’s flagged state.

-- Triggered Script -  Set selection to first child whose name contains "Table of Contents"

-- NOTE: This script triggers every time the record it is attached to is selected. You can: 
--- use the contextual menu by directly right clicking without previously selecting the record,
--- drag the record without previously selecting it,
--- but you can't keep the selection on the record anymore as long as the script is attached.

on triggered(theRecord)
	tell application id "DNtp"
		try
			#if state of theRecord = false then -- I would use something that can be altered via UI as on/off toogle
			set theType to type of theRecord as string
			if theType = "group" or theType = "«constant ****DTgr»" then
				set theChildrenSubset to children of theRecord whose name contains "Table of Contents"
				if theChildrenSubset ≠ {} then
					set selection of viewer window 1 to {item 1 of theChildrenSubset}
				end if
			end if
			#end if
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end triggered


I will try it. thank you very much !

or theType = “«constant ****DTgr»”

This is unnecessary (and likely from Script Debugger).

That might be true in this script, but not in general.

Not sure where and when exactly this happens, however in some situations type as string returns raw syntax. Had a hard time figuring that out.

@cgrunenberg, I just checked the new hint about the type as string issue …

… in the dictionary …

Note: In compiled menu/toolbar scripts you might have to use a string representation of the type for comparisons.

… to show @BLUEFROG that it’s a known issue - but it’s not mentioned :flushed:

Wouldn’t it make sense to add “and its raw syntax”? Without it users get only half of the solution …

… I think.

Not all types require this and only scripts executed by DEVONthink.