Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Applescript to create .MD file of OmniFocus tasks that are due to be completed.
(*
File: OmniFocus_Overdue_Summary.scpt
-------------------------------------------------------------------------------------------------
Revision: 1.03
Revised: 2019-08-01
Summary: Create .md file for list of tasks due and deferred +/- 7d from current date.
-------------------------------------------------------------------------------------------------
Script based on Justin Lancy (@veritrope) from Veritrope.com
http://veritrope.com/code/write-todays-completed-tasks-in-omnifocus-to-a-text-file
-------------------------------------------------------------------------------------------------
*)
--Set Date Functions for file name
set dateYeartxt to year of (current date) as integer
--Fix leading zero's on short day/months
if (month of (current date) as integer) < 10 then
set dateMonthtxt to "0" & (month of (current date) as integer)
else
set dateMonthtxt to month of (current date) as integer
end if
if (day of (current date) as integer) < 10 then
set dateDaytxt to "0" & (day of (current date) as integer)
else
set dateDaytxt to day of (current date) as integer
end if
set str_date to "" & dateYeartxt & "-" & dateMonthtxt & "-" & dateDaytxt
--Set File/Path name of MD file
set theFilePath to ((path to desktop folder) as string) & "To Do List for " & str_date & ".md"
--Get OmniFocus task list
set due_Tasks to my OmniFocus_task_list()
--Output .MD text file
my write_File(theFilePath, due_Tasks)
--Set OmniFocus Due Task List
on OmniFocus_task_list()
set endDate to (current date) + (7 * days)
set endDatetxt to date (short date string of (endDate))
set CurrDatetxt to short date string of date (short date string of (current date))
tell application "OmniFocus"
tell default document
set refDueTaskList to a reference to (flattened tasks where (due date < endDatetxt and completed = false))
set {lstName, lstProject, lstContext, lstDueDate} to {name, name of its containing project, name of its primary tag, due date} of refDueTaskList
set strText to "### To Do List for " & CurrDatetxt & ":" & return & return
repeat with iTask from 1 to count of lstName
set {strName, varProject, varContext, varDueDate} to {item iTask of lstName, item iTask of lstProject, item iTask of lstContext, item iTask of lstDueDate}
if (varDueDate < (current date)) then
set strDueDate to "<span style=\"color:red\">" & short date string of varDueDate & "</span>"
else
set strDueDate to "<span style=\"color:blue\">" & short date string of varDueDate & "</span>"
end if
set strText to strText & "" & strName & " [ _" & varProject & "_ ] " & strDueDate
set strText to strText & return
end repeat
end tell
end tell
strText
end OmniFocus_task_list
--Export Task list to .MD file
on write_File(theFilePath, due_Tasks)
set theText to due_Tasks
set theFileReference to open for access theFilePath with write permission
write theText to theFileReference as «class utf8»
close access the theFileReference
end write_File
-- Use Marked2 app to open MD file automatically
tell application "Marked"
open file theFilePath
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.