omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello β€” I'm @olemoritz on Twitter.


    How to remove or change a calendar event?

    Pythonista
    5
    23
    9046
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @AA737 last edited by cvp

      @AA737 said:

      what would be the format to replace the β€œNone” with a calendar name in the predicate?

      The third parameter of the predicate is not a calendar name but an array of calendars EKCalendar objects.

      1 Reply Last reply Reply Quote 1
      • cvp
        cvp @AA737 last edited by cvp

        @AA737 try this

        calendars_array = [calendar for calendar in store.calendars() if str(calendar.title()) == 'your calendar']
        predicate = store.predicateForEventsWithStartDate_endDate_calendars_(date1, date2, calendars_array)
        events = store.eventsMatchingPredicate_(predicate) 
        
        1 Reply Last reply Reply Quote 1
        • AA737
          AA737 last edited by

          @cvp that worked great, thank you! I have a lot to learn...

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @AA737 last edited by

            @AA737 Believe me, you don't begin with the easiest project πŸ˜€

            1 Reply Last reply Reply Quote 1
            • AA737
              AA737 last edited by

              @cvp Have you noticed you can only run your calendar script about 8 times in a row, and then it stops working and Pythonista has to be reset? Any idea why, or a fix for it?

              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @AA737 last edited by

                @AA737 said:

                run your calendar script about 8 times in a row, and then it stops working

                You're right and I did never see that. I'll check. Perhaps an Apple limitation

                1 Reply Last reply Reply Quote 1
                • cvp
                  cvp @AA737 last edited by

                  @AA737 After testing, I've remarked that after 10 runs (always), there is no crash at all but the returned calendars list of EKEventStore is empty and sincerely, I didn't find anything similar in Google nor any explanation.

                  AA737 1 Reply Last reply Reply Quote 1
                  • AA737
                    AA737 @cvp last edited by

                    @cvp said:

                    @AA737 After testing, I've remarked that after 10 runs (always), there is no crash at all but the returned calendars list of EKEventStore is empty and sincerely, I didn't find anything similar in Google nor any explanation.

                    Interesting, thank you for looking into it, and all your help!

                    cvp 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      @cvp maybe try an autoreleasepool context handler around the code of interest, and then autorelease() and delete the python objects for objc objects you don't need anymore, like the predicate, and maybe the store, calendar arrays, etc. it sounds like ekeventstore gets pissed if you are not releasing its objects.

                      1 Reply Last reply Reply Quote 1
                      • cvp
                        cvp @AA737 last edited by

                        @AA737 Thanks to @JonB , this works

                        import datetime
                        import objc_util
                        
                        with objc_util.autoreleasepool():
                        	
                        	# EKEventStore = calendar database
                        	store = objc_util.ObjCClass('EKEventStore').alloc().init()
                        	
                        	# Convert string yyyymmdd to NSdate
                        	dateFormat = objc_util.ObjCClass('NSDateFormatter').alloc().init()
                        	dateFormat.setDateFormat_('yyyyMMdd HH:mm')
                        
                        	date1 = dateFormat.dateFromString_('20200101 00:01') 
                        	date2 = dateFormat.dateFromString_('20201231 23:59')  
                        
                        	calendars_array = [calendar for calendar in store.calendars() if str(calendar.title()) == 'Sorties']
                        	predicate = store.predicateForEventsWithStartDate_endDate_calendars_(date1, date2, calendars_array)
                        	events = store.eventsMatchingPredicate_(predicate)
                        	for event in events:
                        		print(event.title())
                        		
                        	store.autorelease()
                        	
                        del events, predicate, store, calendars_array 
                        
                        AA737 1 Reply Last reply Reply Quote 1
                        • ccc
                          ccc last edited by

                          To convert from Python datetimes...

                          from datetime import datetime
                          print(f'{datetime.now():%Y%m%d %H:%M}')
                          
                          cvp 1 Reply Last reply Reply Quote 1
                          • cvp
                            cvp @ccc last edited by cvp

                            @ccc I know, but here we need Objectivec NSDateFormatter objects

                            1 Reply Last reply Reply Quote 1
                            • ccc
                              ccc last edited by

                              Yes. My point was about converting from Python datetimes to Objective C datetimes.

                              1 Reply Last reply Reply Quote 1
                              • AA737
                                AA737 @cvp last edited by

                                @cvp said:

                                @AA737 Thanks to @JonB , this works

                                import datetime
                                import objc_util
                                
                                with objc_util.autoreleasepool():
                                	
                                	# EKEventStore = calendar database
                                	store = objc_util.ObjCClass('EKEventStore').alloc().init()
                                	
                                	# Convert string yyyymmdd to NSdate
                                	dateFormat = objc_util.ObjCClass('NSDateFormatter').alloc().init()
                                	dateFormat.setDateFormat_('yyyyMMdd HH:mm')
                                
                                	date1 = dateFormat.dateFromString_('20200101 00:01') 
                                	date2 = dateFormat.dateFromString_('20201231 23:59')  
                                
                                	calendars_array = [calendar for calendar in store.calendars() if str(calendar.title()) == 'Sorties']
                                	predicate = store.predicateForEventsWithStartDate_endDate_calendars_(date1, date2, calendars_array)
                                	events = store.eventsMatchingPredicate_(predicate)
                                	for event in events:
                                		print(event.title())
                                		
                                	store.autorelease()
                                	
                                del events, predicate, store, calendars_array 
                                

                                Fantastic, thanks @cvp and @JonB !

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Powered by NodeBB Forums | Contributors