How to Count the Length of a Variable Array

Thanks to amazing guys on this forum, I use method on this forum to convert text to variable array. Please see the picture below.


I use display text in window to check if it success. The output is OK. But I need to calculate the how many lines are there in this text. I need to find a way to count the length of this array. I don't use For Each Line in the Text with a localCount variable. I want to use other way. I try do this in applescript. Please see the picture below.

The output is 13, not 6. It's not counting how many lines or how many items in this array, it's counting how many characters in total. I cannot find what's wrong. Help people here can help.
QUESTION - return length of variable array.kmmacros (4.2 KB)

Hi @Yu_Cai,

Try this (%Variable%VarName[0]%):

image

I'm surprised this is not documented on the wiki Variables page (maybe it is mentioned somewhere else in the wiki). can @admins add this to the wiki page? I remember someone else asked this question before on the forum.

4 Likes

Wow - that’s news to me!

Can you say where you found this gem?

May also be worth looking at:

[manual:JSON [Keyboard Maestro Wiki]](https://wiki.keyboardmaestro.com:8443/manual/JSON)

1 Like

I forgot where I learned it. I thought the wiki page had it and intended to refer to it, but I did not see it there. The wiki pages are not exhaustive. We continue to find gems here and there, sometime pointed out by a veteran user on the forum, other times Peter shows them.

Yes - it's there alright but it only relates to the use of JSON in KM. It isn't mentioned at all in the context of KM array variables.

Interesting! Cannot believe it can be done in this way. Many thanks.