DT4 - wrong conversion of "text" in Smart Rule AppleScript field

The problem

text

is converted to

rich text

Steps

  1. Open new smart rule

  2. Paste the following code into the text field

text 2 thru -1 of theText

  1. Click on the “eye”

In the end the code is converted to “rich text” which fails to compile.

The complete code of the function:

on trim(theText)
	if length of theText = 0 then
		error "Can't trim empty text." number -1728
	else if length of theText = 1 then
		return ""
	else
		return text 2 thru -1 of theText
	end if
end trim

Development would have to assess this but there are two types of texts in DEVONthink: plain and rich texts.
But why are you using texts here instead of e.g., characters, text items, or words?

i guess one is a synonym of the other.

I misread that earlier as texts but development will still have to assess it. characters 2 thru 1 as string functions in the same way, so I’d opt for that.

text was always rich text and therefore a lot of scripts using as text (or some other form of text) actually should have used as string (as string is plain text) and/or didn’t work as intended. This is more obvious now and avoids also some syntax conflicts of the former script suite.

2 Likes

Found an example on the internet and it worked as expect. :man_shrugging:

rich text fails

String is replaced by strings

The syntax is in both cases not correct, use the one suggested by @bluefrog instead:

characters 2 thru -1 as string