Strings and Lists

For some reason, this code returns “Not a string or a list” even though the variable surely is a string?

set var to "hi"

if var is not string and var is not list then
	return "Not a string or a list"
end if

Why?!

Hi,

var is “hi”, but you"re looking for the class of the variable


set var to "hi"

if class of var is not string and class of var is not list then
	return "Not a string or a list"
end if


Aha! Thanks a lot, I think I understand now!

Also notice that 10.5 and 10.6 behave different with class of x = string

I’m not sure I understand you

Well in 10.5 and higher unicode text, string and text are the same classes. They only keep these class names to be backward compatible with older systems. But on a pre 10.5 system these three classes are different. So when checking if a unicode text is a string will return true on newer system but false on older ones.

set theText to "Dummy" as Unicode text

if class of theText = string then
	--applescript 2.0 and higher (10.5 and newer)
else
	--applescript < 2.0 (10.4 and older)
end if

Ohh! I get it!

I’m doing this as part of an AppleScript-Objective-C Project, which won’t run on 10.6 + anyway.