set TestList to {0, 0, 0, 0, 0, 0}
if every item of TestList is 0 then beep 2
I have also tried:
if (every item of TestList is 0) then beep 2
as well as replacing “is” with “=”
The code as shown above is only an example; as used in the actual code, I am using normal/typical “if, then” structure. It seems to me that this SHOULD work, so any explanation as to why this doesn’t will be greatly appreciated.
The reason it does not work is that “every item” of a list returns just what it says, every item of the list. In your case, {0,0,0,0,0,0}. That does not equal “0”.
You need to loop through the list:
repeat with i from 1 to (count TestList)
if anItem is not 0 then
exit repeat
end if
end repeat
if i is not equal to (count TestList) then beep 2
Just be careful as this will only work if you are trying to test if all the items in the list are zero. It won’t work for any other values (reals, non-zero integers, strings other than 0 as string, etc.).
Right. It’s about as special-case as it can be and is obviously not meant to be taken seriously as an AppleScript technique.
I designed it to work only with integer zeros, but missed that fact that it also fires when the list is completely empty. ({} as string as number = 0 in AppleScript.) So:
set TestList to {0, 0, 0, 0, 0, 0}
if (count TestList's integers) = (count TestList) and TestList as string as number is 0 and TestList is not {} then beep 2