在 OmniFocus2,官方提供了「订阅到日历」选项,可以将带有截止至日历的动作发布到日历应用中。这项功能在 OmniFocus 3 中被移除了

所幸在 Omni Forums 中,@unlocked2412 提供了他写的脚本:

-- 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. 在 macOS 中打开 Script Editor (或者其他编辑器),将代码保存成 .applescript 文件;
  2. 在脚本中的第一行添加自己的日历名称。只要是在 macOS 日历应用中出现的日历都可以。
  3. 将脚本放到 OmniFocus 的脚本文件夹中;
  4. 给动作设定推迟至时间、持续时间、截止时间;
  5. 选中动作后运行脚本即可。



13
2