Estoy tratando de emplear el manejador makeASDate compartido por el usuario CJK (que tomé de su respuesta en Apple script: No se puede obtener la fecha de "2018-12-12 10:00 AM" ) para configurar algunos eventos del calendario, uno por día, a partir de una hoja de cálculo de Números que contenga Fecha, Lectura y Números de Página.
Aquí está mi código, hasta ahora:
set CalendarDates to {}
set CalendarDateMonths to {}
set CalendarDateDatesOfMonths to {}
set Passages to {}
set PageNumbers to {}
set theYear to 2021
tell application "Numbers" to tell the front document to tell the active sheet to tell table 1
repeat with i from 2 to the count of cells of column "A" -- row 1 is a header
set theCalendarDate to formatted value of cell i of column "A"
set theCalendarDateMonth to the first word of theCalendarDate
set theCalendarDateDateOfMonth to the second word of theCalendarDate
set thePassage to formatted value of cell i of column "B"
set thePageNumbers to formatted value of cell i of column "C"
set the end of CalendarDates to theCalendarDate
set the end of CalendarDateMonths to theCalendarDateMonth
set the end of CalendarDateDatesOfMonths to theCalendarDateDateOfMonth
set the end of Passages to thePassage
set the end of PageNumbers to thePageNumbers
end repeat
set theCalendarDate to missing value
set theCalendarDateMonth to missing value
set theCalendarDateDateOfMonth to missing value
set thePassage to missing value
set thePageNumbers to missing value
end tell
repeat with i from 1 to the count of CalendarDates
set theSummary to (item i of Passages)
set theStartDate to makeASDate given |year|:theYear, |month|:(item i of CalendarDateMonths), |day|:(item i of CalendarDateDatesOfMonths), |hours|:7, |minutes|:30
set theEndDate to makeASDate given |year|:theYear, |month|:(item i of CalendarDateMonths), |day|:(item i of CalendarDateDatesOfMonths), |hours|:8, |minutes|:30
set theDescription to "Pages " & (item i of PageNumbers) & "of Tyndale's The Chronological Life Application Study Bible."
set theURL to "https://www.biblegateway.com/passage/?search=" & urlEncode(item i of Passages) & "&version=AMP&interface=print"
set theAlldayEvent to false
set theStampDate to current date
set theStatus to "none"
set theLocation to "facetime:chrishota@gmail.com"
tell application "Calendar"
activate
-- If calendar doesn't exist, create such. Note, this creates local. I don't yet know how to create an iCloud-based Calendar, yet iCloud calendars may be selected if pre-created.
set theCalendarName to "Bible Readings"
try
set theCalendar to (first calendar where its name = theCalendarName)
on error
set theCalendarDescription to "Readings for the reading of the Bible, chronologically, in the span of one year."
set theCalendar to make new calendar with properties {name:theCalendarName, description:theCalendarDescription}
end try
-- Ensure work is with the proper calendar.
set theCalendar to (first calendar where its name = theCalendarName)
tell calendar theCalendar
make new event with properties {description:theDescription, start date:theStartDate, end date:theEndDate, theAlldayEvent:false, stamp date:current date, status:none, summary:theSummary, location:theLocation, url:"http://biblegateway.com/"}
end tell
end tell
end repeat
La hoja de cálculo Numbers se carga correctamente, pero al construir la fecha con MakeASDate, recibo el error "The year parameter is missing for makeASDate".
¡Cualquier ayuda para corregir lo que está mal sería útil!
Edición: He actualizado el código a:
set theStartDate to makeASDate given year:2021, month:(item i of CalendarDateMonths as integer), day:(item i of CalendarDateDatesOfMonths as integer), hours:7, minutes:30, seconds:0
set theEndDate to makeASDate given year:2021, month:(item i of CalendarDateMonths as integer), day:(item i of CalendarDateDatesOfMonths as integer), hours:8, minutes:30, seconds:0
display dialog "CalendarDateMonths[" & i & "]" & ": " & (item i of CalendarDateMonths as integer) & linefeed & linefeed & "theStartDate: " & theStartDate & linefeed & linefeed & "theEndDate: " & theEndDate
Ahora, cuando compilo y ejecuto el código, me devuelve marzo en lugar de febrero cuando introduzco un valor de "2" (he cambiado el formato de la columna Fecha en números para que sea m/d):