I have some code to work with an InDesign file that iterates through the selected objects to pull their parent page IDs and then I want to select the page that is always the right hand page of a spread if there is more than one object on more than one page selected. I thought there might be a built in AS method that finds the maximum value in the list of numbers or properties like page IDs.
Seems not, but I also seem to recall seeing something like
set startPage to item -1 in listOfPages -- where item -1 is the last in a list, item -2 is the second last etc etc
or
set startPage to last item in listOfPages
do I need to sort
the list first, or are last
and item -1
smart enough to do their own implicit sorting lowest to highest?!
here’s the code ChatGTP and I have so far that is not working:
-- Get the current selection
set mySelection to selection
if (count mySelection) is not equal to 0 then
-- Determine the page of the highest-numbered parent page of the selected objects
set parentPages to {}
repeat with selectedObject in mySelection
set parentPage to parent page of selectedObject
if parentPage is not missing value then
set end of parentPages to index of parentPage
end if
end repeat
if (count parentPages) > 0 then
set myPage to last page of parentPages of myDocument
end if
else
-- Use the last visible page of the current spread
set activeSpread to active spread of myDocument
set visiblePages to pages of activeSpread
set myPage to last item of visiblePages -- Last visible page
end if