Listen, you dumb list, you behave!

I am trying to get 3 specific items from a list.

My code:

set page_sequence to the last word of (every page item of every page of document 1 whose label is "SPECS")

Results in a list:
{“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”, “13”, “14”, “15”, “L1”, “L2”, “L3”, “L4”, “R1”, “R2”, “R3”, “R4”, “R5”}

This list varies, and I want to set a variable three times.

I want 1-15 to be variable_1, L1-L4 to be variable_2, and R1-R5 to be variable_3.

I am just now trying to learn repeat loops, and I just can’t seem to wrap my head around how they work. I keep reading tutorials and explanations, but I can’t get it. I have Dyscalculia, so that doesn’t help me AT ALL, but I’m not doing that bad.

This is all in Indesign, and I need 3 different sections to be created in the document, according to whatever page_sequence returns.

Anyone willing to hold my hand and walk me through this?

I know this is reasonably simple, but I think I’m burned out.

( I think I can work out the section hubbub myself, but it’s the repeating through my list that is confounding me…)

Hi,

try this


set theList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "L1", "L2", "L3", "L4", "R1", "R2", "R3", "R4", "R5"}
set numberList to {}
set leftList to {}
set rightList to {}
repeat with anItem in theList
	if anItem starts with "L" then
		set end of leftList to contents of anItem
	else if anItem starts with "R" then
		set end of rightList to contents of anItem
	else
		set end of numberList to contents of anItem
	end if
end repeat

or to get 1-x, L1-Lx, R1-Rx


set theList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "L1", "L2", "L3", "L4", "R1", "R2", "R3", "R4", "R5"}
set leftCounter to 0
set rightCounter to 0
set numberCounter to 0
repeat with anItem in theList
	if anItem starts with "L" then
		set leftCounter to leftCounter + 1
	else if anItem starts with "R" then
		set rightCounter to rightCounter + 1
	else
		set numberCounter to numberCounter + 1
	end if
end repeat
set variable_1 to "1-" & numberCounter
set variable_2 to "L1-L" & leftCounter
set variable_3 to "R1-R" & rightCounter

the second script assumes that there is at least one item in each part

Seeing this just proves how little I understand of this language.

Thank you so much, Stefan!

This works like a charm. The first one appears to be the best fit for what I need, as I can make the script ignore the sections that are empty. Sometimes, for example, I will receive a list that is all numbers, or that only has R’s and L’s.

Thanks again!