Using Arrays to Simplify Script of Repetitive Tasks

[Sigh.] Thanks. Done.

Works great, thanks so much Nigel!

Trying to better understand arrays, and so out of curiosity, if you wanted to perform only one task to a group of separated columns, is it possible to use a straight and easy line like this, or would you always have to load your columns into a variable and use a repeat statement to cycle through them?

set alignment of column {"A", "E", "G"} to left

When you want set array of properties to the SAME value, you can avoid repeat loop.
 

tell application "Numbers" to tell table 1 of sheet 1 of document 1
	set aRange to range ("A1:G" & (count rows))
	set alignment of columns of aRange to right
end tell

 

Looking to only set the alignment of certain columns that are not in a range, though (Columns A, E, and G in this example), so wondering if those column letters can be listed in a single array and have the alignment property applied to each of them.

This is impossible in the Numbers

Realize that this as posted is not correct, but wanted to know if something similar is possible.

This is impossible in the Numbers without repeat loop

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
	set theColumns to {"A", "E", "G"}
	repeat with eachColumn in theColumns
		tell range eachColumn
			set alignment to left
		end tell
	end repeat
end tell

That does the trick - so the lesson learned is yes, you can use an array to keep the script short and tidy, but no, you cannot avoid using the repeat loop for execution. In other words, Applescript doesn’t internally know that you want to apply the format to each column inside the array without explicitly saying so with the repeat loop.

That only works for a contiguous column range, though. The idea of the array is to apply the format to various non-aligned columns.

Avoiding the use of a repeat loop in Numbers when setting property values still doesn’t make sense. Since Numbers updates them one by one when scripting it.

Understood, just thought that perhaps Numbers knows when applying a format to an array of column letters that it needs to loop it on its own, and apparently it doesn’t.