Problems with {12.0, 3.0, 0.0, 0.0} within a list.

Hi
I have the following script, to delete rectangles with specific color fills, which works well

set TheOtherFrames to every rectangle of every spread
		set OtherFramesCount to count of TheOtherFrames
		repeat with i from 1 to OtherFramesCount
			set TheOtherFrame to item i of TheOtherFrames
			set TheOtherFrameColor to fill color of TheOtherFrame
			set TheOtherFrameColorValue to color value of TheOtherFrameColor
			
if TheOtherFrameColorValue is {12.0, 3.0, 0.0, 0.0} then
				delete TheOtherFrame

etc…

Now I want to make a list (DeleteUs) of color values but AS ignores my list even though the result looks OK.
Should I use other brackets? I have tried several… :confused:

set TheOtherFrames to every rectangle of every spread
		set OtherFramesCount to count of TheOtherFrames
		repeat with i from 1 to OtherFramesCount
			set TheOtherFrame to item i of TheOtherFrames
			set TheOtherFrameColor to fill color of TheOtherFrame
			set TheOtherFrameColorValue to color value of TheOtherFrameColor
			set DeleteUs to {{12.0, 3.0, 0.0, 0.0}, {40.0, 10.0, 0.0, 0.0}}
			
			if TheOtherFrameColorValue is in DeleteUs then
				delete TheOtherFrame
				
			end if
			return DeleteUs

I get this result:
{{12.0, 3.0, 0.0, 0.0}, {40.0, 10.0, 0.0, 0.0}}

Looks OK (?) but no delete…

Hi.

If you want to know if a list contains another list or a record, you have to write it like this:

if {TheOtherFrameColorValue} is in DeleteUs then
	delete TheOtherFrame

end if

ie. with braces round the possibly contained list. This is because the ‘is in’ and ‘contains’ commands treat the search value as a section of a list rather than as an item contained within it:

{1, 2, 3} is in {1, 2, 3, 4, 5, 6} --> true
{1, 2, 3} is in {{1, 2, 3}, {4, 5, 6}} --> false
{{1, 2, 3}} is in {{1, 2, 3}, {4, 5, 6}} --> true

This is officially true when looking for any item in a list, but since AppleScript coerces the search item to list automatically, it’s only necessary to use braces when checking for lists and records.

1 is in {1, 2, 3, 4, 5, 6} --> true
{1} is in {1, 2, 3, 4, 5, 6} --> true

{a:7} is in {1, 2, 3, 4, 5, 6, {a:7}} --> false
{a:7} is in {1, 2, 3, 4, 5, 6, 7} --> true!
{{a:7}} is in {1, 2, 3, 4, 5, 6, {a:7}} --> true

YES! This did the trick…
Big thanks for the help and explanation Nigel.
I was kind of going mad not getting it right :slight_smile:
Cheers
Johan

This was very interesting:
{a:7} is in {1, 2, 3, 4, 5, 6, {a:7}} → false
{a:7} is in {1, 2, 3, 4, 5, 6, 7} → true!
{{a:7}} is in {1, 2, 3, 4, 5, 6, {a:7}} → true

…and well explained!