AppleScriptStudio Lists Help

After working on this problem for over an hour, I still can’t figure out how to get the number of items in a list - and display that number in a text field. For some reason this code doesn’t work (though it should) and is the same code that I normally use for regular AppleScript. This code when run displays a “the variable bla is not defined” error though the var bla is clearly defined before the “set contents” code.

Code:

property asdf : {“a”, “b”}
on clicked theObject
set bla to number of items of asdf
set contents of text field “text” to bla
end clicked

Thanks in advance…

Uhhhm… strange.

Why don’t you try this :

property asdf : {"a", "b"}
on clicked theObject
    set bla to (count of asdf)
    set contents of text field "text" to bla
end clicked

It seems to work if you do it like this, just run this in the Script Editor :

property asdf : {"a", "b", "c","d"}
on run
	set bla to (count of asdf)
	display dialog bla
end run

It should work, so good luck with your thing :wink:

BS0D

Hi,

to count the items of a list better use the keyword count, or this syntax


set bla to number of (get items of asdf)

it’s always recommended to use the appropriate command ro assign different classes to a text field,
in this case the variable bla contains a number (integer)


property asdf : {"a", "b"}
on clicked theObject
	set bla to count asdf
	set integer value of text field "text" to bla
end clicked

Thanks StefanK and BSOD for the prompt replies! Now I can finally get back to the programming…