What should `type of record` return for text records?

If I have a text record (r) selected and do this

set t to type of r
set weird to (t is not txt)

then weird is in fact true. Which is weird, since the documentation (aka function library in Script Editor) clearly states that the type of a record should be txt. Or maybe I’m not understanding it correctly. So let’s try this:

set weird to (t is not text)

which again results in true, so more weirdness.
But it get’s more interesting:

set weird to t as string

results in "text". So converting a type that is neither txt nor text to a string gives “text”?

Even more interesting: Trying the exact same code in JavaScript like so

(()=> {
  const app = Application("DEVONthink 3");
  const r = app.selectedRecords()[0];

tells me that r.type() is undefined. It is getting curiouser and curiouser.

The documentation says also re type:
“The type of a record. Note: In compiled menu/toolbar scripts you might have to use a string representation of the type for comparisons.”
which I do not find particularly enlightening. What is “a string representation of the type” - the same as as string respectively toString()? In this case, how am I going to convert undefined to a meaningful string in JavaScript?

Now I convert this exact same record (that has no content whatsoever, BTW) to markdown in DT. And voilá, r.type() in JavaScript is no longer undefined but "markdown".

I could imagine that somehow the “txt/text” thingy gets caught up in reserved words in either AppleScript and/or JavaScript and that this results in the rather irritating behaviour. Maybe it would be possible to change this identifier to something like “pureText” or whatever? Given that the current one does not work as expected/announced anyway, that shouldn’t break too many scripts.

1 Like

Just checked this and the next release will fix this.

1 Like