I’m self-taught in AppleScript, & hope I’m expressing this clearly.
I’m trying to assign record property values in a repeat loop as part of a larger script, but can’t figure out how to reference the property values consecutively:
global docNamePartsList, dateSetList
set yearFormat to 2
set dateSetList to {component:{|day|:missing value, |month|:missing value, |year|:missing value}, |string|:{"Day (1-31)", "Month (1-12)", "Year (2 or 4 digits)"}, format:{|day|:2, |month|:2, |year|:yearFormat}, limit:{31, 12, null}}
--UNCOMMENT THE VERSION I WANT TO USE
--set dateSetList to my SetNameAndDateFromUserInput()
--set dateSetList to my SetNameAndDateFromUserInput_v2()
set dateSetList to my SetNameAndDateFromUserInput_v3(component of dateSetList)
on SetNameAndDateFromUserInput()
--WANT TO USE REPEAT LOOP TO SET ITEMS IN LIST TO USER-INPUT VALUES
local n
--n IS NUMERICAL REFERENCE TO LIST ITEM I WANT TO ADDRESS
repeat with n from 1 to 3
set item n of component of dateSetList to text returned of (display dialog "Enter " & (item n of |string| of dateSetList) default answer "") as number
end repeat
return dateSetList
end SetNameAndDateFromUserInput
but when I use numbers (item n of…) it throws an error:
Can’t set item 1 of {|day|:missing value, |month|:missing value, |year|:missing value} to 3
BUT it has no trouble reading a number reference (item n of |string| of dateSetList) for the prompt in the dialog. The dialog displays with the prompt as specified & lets me enter the value. If I skip over the error & move on to the next iteration, the next |string| value displays, as expected.
I thought maybe the nested lists were causing a problem, so I tried jumping through increasingly convoluted hoops; first, breaking up into the individual lists:
on SetNameAndDateFromUserInput_v2()
--WANT TO USE REPEAT LOOP TO SET ITEMS IN LIST TO USER-INPUT VALUES
local i, n
--i IS THE SUB-LIST BEING ADDRESSED
--n IS NUMERICAL REFERENCE TO SUB-LIST ITEM I WANT TO ADDRESS
set i to component of dateSetList
repeat with n from 1 to 3
set item n of i to text returned of (display dialog "Enter " & (item n of |string| of dateSetList) default answer "") as number
end repeat
set component of dateSetList to i
return dateSetList
end SetNameAndDateFromUserInput_v2
Same result. Then, I tried iterating through list items directly:
on SetNameAndDateFromUserInput_v3(aList)
--WANT TO USE REPEAT LOOP TO SET ITEMS IN LIST TO USER-INPUT VALUES
local aList, i, j, n
--aList IS THE SUB-LIST BEING ADDRESSED, PASSED FROM THE CALLING STATEMENT
--i IS A HOLDER FOR THE CURRENT STATE OF THE SUB-LIST
--j IS THE CURRENT ITEM OF LIST i BEING ADDRESSED
--n IS NUMERICAL REFERENCE TO ITEM I WANT TO ADDRESS
set i to aList
set n to 0
repeat with j in i
set n to n + 1
set j to text returned of (display dialog "Enter " & (item n of |string| of dateSetList) default answer "") as number
set item n of i to j
end repeat
return aList
end SetNameAndDateFromUserInput_v3
but even though I’m assigning my repeat variable directly to the list item, the script still interprets it as item # of…, throwing the error; AND each time, in the dialog prompt string, it references a numbered item in another similar sub-list correctly.
This seems inconsistent. How do I get it to identify the list item in the target list by number, as it’s doing w/the similar reference in the dialog prompt string? What am I not getting? Thanks for your help.