Remove all alarms of all overdue reminders with AppleScript on OS X

applescriptreminders

I want to remove all alarms / notifications (there may be none, one or more than one) of all overdue reminders in the Reminders app of OS X.

I tried to use AppleScript for this, but having troubles understanding how to properly work with objects. I figured out how to get all those reminders, though:

tell application "Reminders"
    activate
    set myRemList to every reminder whose due date is less than (current date) as list
    repeat with myitem in myRemList
        log (get properties of myitem)
    end repeat
end tell

Is this code usable (any fatal mistakes I'm not aware of)? How can I remove the alarms?

[Edit]

Here's an example of what I want to achieve:

Consider this one which reminds me to call Jon Doe:

enter image description here

The item is due today and a reminder is set to notify me at 14.00 (2 pm). When my planning has changed there are few of those items, popping up their reminders ("call jon doe" in this example). I want that "remind me" property to be unticked for all overdue items.

Best Answer

There was no fatal mistake in the code shown in the OP, however the proper way to use current date, in this case, is by letting the current application do it, not Reminders, as it actually errors out but does recover, hence not fatal. Nonetheless one should write code that's not going to needlessly error out. So, before the tell application "Reminders" code block, set current date to a variable and use the variable within the Reminders code block, as shown in the code further below.

Note that I personally do not use the Reminders app, however going by what's exposed in Reminders's AppleScript Dictionary, the following properties, not marked asr/o, are what can be programmatically changed for the reminder class.

name (text) : the name of the reminder
id (text, r/o) : the unique identifier of the reminder
body (text) : the notes attached to the reminder
completed (boolean) : Is the reminder completed?
completion date (date) : the completion date of the reminder
container (list, r/o) : the container of the reminder
creation date (date, r/o) : the creation date of the reminder
due date (date) : the due date of the reminder
modification date (date, r/o) : the modification date of the reminder
remind me date (date) : the remind date of the reminder
priority (integer) : the priority of the reminder

As a test, I created a reminder named "Test" and set the remind me [√] check box to yesterdays date, so as to conform with the search parameter in the code further below.

Then, in Script Editor, I used the following line of code to get its properties.

tell application "Reminders" to get properties of reminder named "Test"

It returned:

  • {due date:date "Saturday, September 10, 2016 2:00:00 PM", modification date:date "Sunday, September 11, 2016 1:49:35 PM", class:reminder, body:missing value, completed:false, completion date:missing value, id:"3F0EF538-5DF6-4F1C-8024-922B5D45EB9B", name:"Test", container:list id "9EB58C9B-EF63-4B72-88C3-A4FFA3C7272F" of application "Reminders", priority:0, creation date:date "Sunday, September 11, 2016 1:49:13 PM", remind me date:date "Saturday, September 10, 2016 2:00:00 PM"}

I then manually unchecked the remind me [] check box and ran the ... get properties ... code again.

It returned:

  • {due date:missing value, modification date:date "Sunday, September 11, 2016 1:49:35 PM", class:reminder, body:missing value, completed:false, completion date:missing value, id:"3F0EF538-5DF6-4F1C-8024-922B5D45EB9B", name:"Test", container:list id "9EB58C9B-EF63-4B72-88C3-A4FFA3C7272F" of application "Reminders", priority:0, creation date:date "Sunday, September 11, 2016 1:49:13 PM", remind me date:missing value}

The primary difference between the two was the first and last items in the list, i.e., the due date and the remind me date, went from due date:date "Saturday, September 10, 2016 2:00:00 PM" to due date:missing value with the same for remind me date, having remind me date:missing value too.

So I tested the code below using both preferences, due date and remind me date just to see if there was any difference and there wasn't, as removing one removed the other.

The following code will remove both the due date and remind me date from any Reminder that's older then current date and has not been marked completed, at the time the code is run, as this is what occurs, at least to the properties of a reminder, in one has manually unchecked the remind me [] check box.

set curDate to current date

tell application "Reminders"
    activate
    set myRemList to every reminder whose due date is less than curDate as list
    repeat with myitem in myRemList
        if completed of myitem is false then
            delete remind me date of myitem
        end if
    end repeat
end tell

The code above can also be written as shown below. This actually is a better way to write it, as it makes for a smaller list returned because it's then only creating a list of items (reminders) that have not yet been marked as completed. As after all, ones already marked as completed are not going to trigger an "alarm".

set curDate to current date

tell application "Reminders"
    activate
    set myRemList to every reminder whose completed is false and due date is less than curDate as list
    repeat with myitem in myRemList
        delete remind me date of myitem
    end repeat
end tell

Based upon your edited OP, if this does not do what is needed, then I do not know what else I can offer, as I can only work within what properties are exposed and editable.

Note: I was not able to reproduce the reminder as shown in your edit, i.e. the line starting with "due" directly under the [] At a Location check box and above "repeat None". However, what is now offered as the answer to "remove all alarms of all overdue reminders with AppleScript on OS X" does mimic the manual action of unchecking the remind me [] check box, which is what you've now asked for through the edit made to the OP. I hope this resolves your issue.