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?
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.
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
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?
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?
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: