Struggling With Rose's Omni and Calendar Keyboard Maestro/AppleScript

Hi All,
I’ve been attempting to implement @RosemaryOrchard 's Keyboard Maestro trick to get all OmniFocus tasks with due dates and add them to a calendar. When it works, it works beautifully. However, half the time it doesn’t make it past the “delete all events” part of the script, giving me:

Result:

error “Calendar got an error: Can’t get event id “88013D6F-C221-4F8E-A12D-072A1A1AEEEC” of calendar id “E8F90DD0-46A1-450D-AE8F-244E22957A92”.” number -1728 from event id “88013D6F-C221-4F8E-A12D-072A1A1AEEEC” of calendar id “E8F90DD0-46A1-450D-AE8F-244E22957A92”

I’ve found that if I go through and delete a handful of events from my OmniFocus calendar, it generally runs well the next time. However, that isn’t useful when I’m away from my Mac… Plus, my calendar app seems to freeze any time I’m using it in Keyboard Maestro, but not when I’m running it from Script Editor (I can’t figure out a link, but it’s happened too many times to be coincidental).

Here’s a copy of the script, does anyone have any ideas?

property calendar_name : “OmniFocus” – This is the name of your calendar

property default_duration : 30 --minutes

tell application “Calendar”

set calendar_element to calendar calendar_name

tell calendar calendar_name

set theEvents to every event

repeat with current_event in theEvents

delete current_event

end repeat

end tell

end tell

tell application “OmniFocus”

tell default document

set task_elements to flattened tasks whose ¬

(completed is false ) and (due date ≠ missing value )

repeat with item_ref in task_elements

– GET OMNIFOCUS TASKS

set the_task to contents of item_ref

set task_name to name of the_task

set task_note to note of the_task

set task_due to due date of the_task

set task_estimate to estimated minutes of the_task

set task_url to “omnifocus:///task/” & id of the_task

if task_estimate is missing value then set task_estimate to default_duration

– BUILD CALENDAR DATE

set end_date to task_due

set start_date to task_due - (task_estimate * minutes)

– CREATE CALENDAR EVENT

tell application “Calendar”

tell calendar_element

if not ( exists ( first event whose (start date = start_date) and (summary = task_name))) then

make new event with properties ¬

{summary:task_name, start date:start_date, end date:end_date, url:task_url} at calendar_element

end if

end tell

end tell

end repeat

end tell

end tell

my script looks exactly the same, and has an almost 100% success rate.

What time have you set it to fire off?

I didn’t put it on the hour but at :55 so it doesn’t conflict with time capsule (or other events) firing off.

I had it on the hour, but I’ll give it a try!

curious to see if that’s it
good luck :slight_smile: