issue detecting txt record type

I don’t seem to be able to test if a record is a plain text file. With “theRecord” set to the record of a plain text file, the following evaluates to false …

tell application "DEVONthink Pro"
	type of theRecord = txt
end tell

According to the documentation, the name of the type is “txt”. When I evaluate the following in the AppleScript Editor …

tell application "DEVONthink Pro"
	type of theRecord
end tell

… I get “text” in a purple font. But evaluating …

tell application "DEVONthink Pro"
	type of theRecord = text
end tell

… also results in false. Help please. Thanks.

Try this.


tell application id "com.devon-technologies.thinkpro"
try
set this_item to the selection
if type of this_item is txt then
-- do something important
else
-- do something less important
end if
end try
end tell

The case here is a single record is selected.

I had to make some modifications to get the script to run. Here is the script I used.

tell application id "com.devon-technologies.thinkpro2"
	try
		set this_item to the selection
		if type of item 1 of this_item is txt then
			display alert "yes"
		else
			display alert "no"
		end if
	on error msg number num
		display alert msg
	end try
end tell

I get an alert saying “no” when I run it with a single plain text file selected in DT.

You’re right. Very strange.

Using Kind works. Try this.

tell application id "com.devon-technologies.thinkpro2"
	try
		set theDatabase to current database
		set these_items to the selection
		repeat with this_item in these_items
			set myType to (type of this_item as string)
			if kind of this_item is "Text" then
				display alert "yes, Type: " & myType
			else
				display alert "no, Type: " & myType
			end if
		end repeat
	end try
end tell

Yep, kind appears to be working for me. Thanks for the help.

Kind might depend on the localization and the extension and is therefore not recommended. However, this should always work:


	if ((type of theRecord) as string) is "text" then

Probably an issue caused by the arbitrary syntax of AppleScript.

Thanks, Christian. Sometimes AppleScript is blindingly unintuitive. 8)

Indeed :mrgreen: