Forum Archive

Reminders module - priority attribute

dakadagm7

Does anyone know if there is a way to access the priority attribute in the Reminders module. It isn’t included in the omz Reminders module documentation but Im hoping it could be added.

cvp

@dakadagm7 via Objectivec

from objc_util import *

# EKEventStore = calendar database
store = ObjCClass('EKEventStore').alloc().init()

EKReminder = ObjCClass('EKReminder').reminderWithEventStore_(store)

EKReminder.priority = 2
EKReminder.title = 'test'
EKReminder.setCalendar_(store.defaultCalendarForNewReminders())

# store modified reminder in calendar
store.saveReminder_commit_error_(EKReminder,True,None)
cvp

@dakadagm7 If you want to use Pythonista reminders module for other attributes and methods, you can add this kind of code to only use Objective-c for setting priority

from objc_util import *
import reminders

def test():
    # EKEventStore = calendar database
    store = ObjCClass('EKEventStore').alloc().init()
    def_cal = store.defaultCalendarForNewReminders()

    tit = 'added via Pythonista'

    # Get unique identifiers of all existing reminders with this title  
    predicate = store.predicateForRemindersWithTitle_calendars_(tit,[def_cal])  
    EKReminders = store.remindersMatchingPredicate_(predicate)
    existing_uids = []
    for EKReminder in EKReminders:
        existing_uids.append(str(EKReminder.uniqueIdentifier()))
    print(existing_uids)

    r = reminders.Reminder()
    r.title = tit
    r.save()

    # Get all existing reminders with this title
    predicate = store.predicateForRemindersWithTitle_calendars_(tit,[def_cal])  
    EKReminders = store.remindersMatchingPredicate_(predicate)
    for EKReminder in EKReminders:
        if str(EKReminder.uniqueIdentifier()) not in existing_uids:
            # this reminder is the just added one
            EKReminder.priority = 3
            # store modified reminder in calendar
            store.saveReminder_commit_error_(EKReminder,True,None)
            break

test()
cvp

@dakadagm7 Will be in next version, see here