I still can’t figure out the ASObjC syntax for setting an Objective-C @property in AppleScript. I had a few unsuccessful attempts at it, but I won’t embarass myself by posting them.
If the property is
dueDateComponents, you use setDueDateComponents:newValue.
Suffice to say, if anyone can offer pointers, thoughts, objections, or just plain rumours, on how one might set the due date on an existing reminder (not a new one, mind you!), they’d be much appreciated (Oh, and do remind me to set a reminder not to try scripting Reminders again).
EventKit is not for the faint-hearted. Nevertheless, this probably does what you want, using normal AS to get the ID:
use framework "Foundation"
use framework "EventKit"
on setDueDate:ASDate forReminderID:theID
set theNSDate to my makeNSDateFrom:ASDate -- convert date to Cocoa using handler
set theCalendar to current application's NSCalendar's currentCalendar() -- get calendar
set theComponents to theCalendar's componentsInTimeZone:(current application's NSTimeZone's localTimeZone()) fromDate:theNSDate -- get date components of date
set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:1 -- get event store; 1 means reminders
set theReminder to eventStore's calendarItemWithIdentifier:theID -- get the reminder
theReminder's setDueDateComponents:theComponents -- set due date
eventStore's saveReminder:theReminder commit:true |error|:(missing value) -- save
end setDueDate:forReminderID:
on makeNSDateFrom:theASDate
set {theYear, theMonth, theDay, theSeconds} to theASDate's {year, month, day, time}
if theYear < 0 then
set theYear to -theYear
set theEra to 0
else
set theEra to 1
end if
set theCalendar to current application's NSCalendar's currentCalendar()
set newDate to theCalendar's dateWithEra:theEra |year|:theYear |month|:(theMonth as integer) ¬
|day|:theDay hour:0 minute:0 |second|:theSeconds nanosecond:0
return newDate
end makeNSDateFrom:
use theLib : script "<name of script>"
use scripting additions
tell application "Reminders" to set theID to id of reminder 1
set theID to text 20 thru -1 of theID -- strip to just id
theLib's setDueDate:((current date) + (2 * days)) forReminderID:theID