Applescript for syncing OF tasks to Apple Calendar

Hi,

As the OF sync with Apple Calender is no help at all, i was wondering if someone has a script available that simply copies and updates every task that has an estimated duration and a due date and time to the native Apple Calendar. If a task takes 25 mins, it needs to be shown as a 25 minute event in my calendar and on the right date and time f course.

Love to hear if anyone has a solution for this one!

Ralph

@ravadeI don’t know about scripts for this purpose but I do know for a fact that you can drag an OF2 task (with est time) & drop on the appropriate date in Fantastical and Fantastical will respect the est’ time you asked for.
I use this method frequently to make my day work smoothly.

I made this draft. Maybe it helps.
You need to enter your calendar name in the property calendar_name.
Note: It would be painfully slow in calendars with lots of events.

-- unlocked2412
-- THIS SCRIPT MAKES CALENDAR EVENTS FROM OMNIFOCUS TASKS WHOSE
-- DUE DATES AND ESTIMATED MINUTES FIELDS HAVE VALID VALUES.

property calendar_name : "" -- ENTER NAME OF YOUR CALENDAR

tell application "Calendar"
	set calendar_element to calendar calendar_name
end tell
tell application "OmniFocus"
	tell default document
		set task_elements to flattened tasks whose ¬
			(completed is false) and (estimated minutes ≠ missing value) 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
			-- BUILD CALENDAR DATE
			set start_date to task_due
			set end_date to start_date + (task_estimate * minutes)
			-- CREATE CALENDAR EVENT
			tell application "Calendar"
				tell calendar_element
					if exists (first event whose (start date = start_date) and (summary = task_name)) then
						tell application "System Events"
							display dialog "The task: " & task_name & " is already in your calendar"
						end tell
					else
						make new event with properties ¬
							{summary:task_name, start date:start_date, end date:end_date} at calendar_element
					end if
				end tell
			end tell
		end repeat
		tell application "System Events"
			display dialog "Done"
		end tell
	end tell
end tell
1 Like