tell application "Reminders"
set ddList to the due date of every reminder
end tell
set ds to the date string of (current date)
set c to 0
repeat with d in ddList
if d does not contain missing value then
if date string of d contains ds then
set c to c + 1
end if
end if
end repeat
return c
But I would also include the reminders not completed with a due date in the past ( and so obtain the number of elements in the Today smart list).
I've not used Reminders much, so there may be some gotchas my quick testing didn't catch, but this should work:
tell application "Reminders"
set theList to first item of (get every list)
set dueReminders to every reminder of theList whose due date ≤ (get current date) and completed is false
return length of dueReminders
end tell
You'll have to set the list to be checked if you have more than one, and this'll return the number of "due" items for you to use later in your macro. It wouldn't take much to include multiple lists in one result, multiple results for multiple lists, etc.
-- Set target to the upcoming midnight
set target to (current date) + 1 * days
set time of target to 0
-- Get all the uncompleted reminders due before the target and return their count
tell application "Reminders"
set dueList to every reminder whose due date < target and completed is false
get length of dueList
end tell
This matches what you'l find in the Today smart list in that it collects all of the uncompleted reminders in all of the lists that have due dates within the current day. The two lines at the top use AppleScript's weird date arithmetic to set the target variable to the upcoming midnight.
AppleScript's current date command returns a date/time stamp that includes the current time, so your script collects reminders with due dates at or before the date/time at which your script is run. I did exactly the same thing until I saw that my script wasn't counting reminders that were due later today. That's when realized I had to fiddle with target to get it to include everything up until midnight.
Thank you so much for your answers!
I just tested it, it seems to give the result I wanted.
I had found some explanations on the management of dates in Applescript but I confess that it was very complicated for me.
Your solution is 'simple' . Great ...
AppleScript actually makes a lot of date handling very easy -- once you get used to the syntax!
In this case, we don't even care about the format of the date, just that a date "object" can be retrieved from each Reminder. That object will include both date and time the Reminder is due.
Because you want things that are due "today or earlier", we have to look ahead to find Reminders that are due before tomorrow, and the easiest way to do that is to set our test date to "now", add a day, then set the time of the new day to 0, so we have an object representing "midnight tonight/tomorrow morning".
Doing that all to the date object means AppleScript takes care of "Is tomorrow a new month? A new year?", so we don't have to...