Selection whose type is (in devonthink 2)

I am trying to generate a list from a selection of records that match a particular property (eg type is markdown) without resorting to a repeat loop.

set markdownRecords to (items of selection whose type is markdown)

Unfortunately, this generates an error:
error "Can’t get selection of application \"DEVONthink Pro\" whose type = markdown. Access not allowed." number -1723

After searching through some threads here, I have noticed a few examples of something similar in DT3 but nothing that would work in v2 (2.11.3). For example in this post:

repeat with theRecord in (selected records whose (type is markdown))

Of course, there is no selected records in DT2.

Sometimes I have found that you can use a reference to in such a scenario but not in this particular one.

My purpose here is to simplify a library script that returns a list of markdown records regardless of the nature of the frontmost window. I then have a bunch of scripts that will work with the listed records.

Here is that script:

tell application id "DNtp"
	set fw to front think window
	
	if (class of fw) is document window then
		if type of record of window id (id of fw) is markdown then
			set returnedList to (record of fw as list)
		end if
		-- display dialog winClass as text giving up after 2 -- "document window"
	else
		-- display dialog winClass as text
		if selection of fw is not {} then
			set selectionList to selection of fw
			set returnedList to {}
			repeat with sel in selectionList -- each selected record
				if type of sel is markdown then
					set end of returnedList to content id (id of sel) of database id 2 -- list of markdown to be returned
				else
					display dialog "record is not markdown" with icon caution giving up after 2
				end if
			end repeat
		end if
	end if
	return returnedList --> content id 339246 of database id 2
	
end tell

Any suggestions or is this not possible with DT2? Thanks.

No, this is not possible with DEVONthink 2.x without a repeat loop. Also, version 2.x is long out of development, so this will not change in the future.

My purpose here is to simplify a library script that returns a list of markdown records regardless of the nature of the frontmost window

This statement doesn’t seem to make sense in the context of your inquiry. If you’re trying to process selected items, they logically have to be part of a window. Are you saying you want to handle the selection in a background window?

1 Like

I wouldn’t expect anything to change at this point. Eventually I’ll upgrade.

No, I just want it to work the same regardless of which type of window is frontmost (search, viewer, document) — but if I can have it work without a repeat loop then it would be simpler, especially where the dialog appears to let me know that not all selected records are markdown. I use the above script in a library and it returns a list of markdown records to whichever script calls it. If an individual record is open and frontmost, then it would be a list of 1.

I saw a post from someone else regarding find and replace in markdown documents. I have a few scripts which work similarly but I noticed that this other script used whose filtering but it uses an unavailable command so I thought I would enquire.