Help determining the record type in a script

Please excuse if wrong terminology is used.

To determine the record type, is it markdown, pdf, formatted note etc it seems that the type property is used.

The way the type property is defined in the documentation is that it is a type2
type2 (enumeration)
WHERE USED
The type2 enumeration is used in the following ways:
type property of the record class/record

So to determine if the document is a markdown document I code

if type of theRecord is markdown then
	display alert "a markdown"
end if

where theRecord references a record.

This works fine.

What does not work is

if kind of theRecord is formatted note then
	display alert "a note"
end if
if kind of theRecord is text then
	display alert "a text"
end if

The way I got it to work is the following.

if kind of theRecord = "text" then
	display alert "a text"
end if
if kind of theRecord = "Formatted Note" then
	display alert "a formatted note"
end if

Can you please explain why this is the case.Why do I need to change the syntax to = and compare it to the way that I did?

Thanks
Steven

I noticed in your example you switched to the “kind” field
From the Applescript dictionary

kind (text, r/o) :
The human readable and localized kind of a record.
WARNING: Don’tuse this to check the type of a record, otherwise your script might fail depending on the version and the localization.

type (bookmark/​feed/​formatted note/​group/​html/​markdown/​PDF document/​picture/​ plist/​quicktime/​rtf/​rtfd/​script/​sheet/​smart group/​txt/​unknown/​webarchive/​xml, r/o) :
The type of a record.
Note: In compiled menu/toolbar scripts you might have to use a string representation of the type for comparisons.

thanks @DTLow

So when I use type with formatted note it works

if type of theRecord is formatted note then
	display alert "a note"
end if

But for text it does not work.

if type of theRecord is txt then
	display alert "a txt"
end if

Any ideas why?

This is what I did to make it work

set thisType to (type of theRecord) as string
if thisType is in {"txt", "«constant ****ctxt»"} then display alert "yay a text"

Is there a better way?

Any comments would be appreciated.

Steven

It is text, not txt, I think

@chrillek thanks for your input.

I did not find that text works.

I tried

set thisType to (type of theRecord) as string
if thisType is in {"text"} then display alert "100 a text"

if type of theRecord is text then
	display alert "a text"
end if

and neither worked.

Sorry, I didn’t read the other post thoroughly enough. Of course, according to documentation, “txt” should work. But I remember @pete31 having some problems with type, too. May be searching for his posts in this context helps?

If I do this

tell application id "DNtp"
	set r to first item of selected records
	set t to type of r
        set foo to t as string is in {"text"}
end tell

in Script Editor, I get “true”. Also, your code (ìf … display alert …` works fine over here.
Can you show the messages of Script Editor when you run the code?

OK, based on what you said I think I am finally figuring it out.

Yes “text” does work in a regular script but not when I run it as a smart rule execute script external action. on performSmartRule(theRecords)

set thisType to (type of theRecord) as string
if thisType is in {"text"} then display alert "100 a text"

Does not seem to work when doing it as a smart rule execute script external action but does when doing it as a regular script,

So finally AppleScript is behaving weirdly in the context of external smart rule scripts, too.

This is of course no consolation for you, unfortunately. But since @cgrunenberg announced a cleaned up smart rule behaviour for JavaScript in one of the next releases, this might also help in your case. Also, the whole txt type thing is weird anyway:

OK. I guess that’s what it is.

@chrillek thanks for your help and your post about this issue. Very useful

Steven