Skip to content

Instantly share code, notes, and snippets.

@benwaldie
Created January 14, 2013 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwaldie/4527422 to your computer and use it in GitHub Desktop.
Save benwaldie/4527422 to your computer and use it in GitHub Desktop.
TUAW > Send OmniFocus Due Tasks to iTunes
-- Set this property to the perspective you want to process
property thePerspectiveName : "Due"
-- Set up a variable for the task list text
set theTaskList to ""
-- Target OmniFocus
tell application "OmniFocus"
activate
-- Target the front OmniFocus window
tell front window
-- Display the perspective
set perspective name to thePerspectiveName
-- Loop through any trees in the perspective
tell content
repeat with a from 1 to count trees
set theCurrentTree to tree a
-- Target the current tree
tell theCurrentTree
-- Retrieve the tree's name and tasks
set theCurrentTreeName to name
set theCurrentTreeTasks to every descendant tree
-- Add the current tree's name to the task list text
set theTaskList to theTaskList & theCurrentTreeName & return & return
-- Loop through the current tree's tasks
repeat with b from 1 to length of theCurrentTreeTasks
set theCurrentTask to value of item b of theCurrentTreeTasks
-- Target the current task
tell theCurrentTask
-- Retrieve the task's name parent project name
set theCurrentTaskName to name
if containing project exists then
set theProjectName to name of containing project
-- Create suffix text containing the current project name
set theProjectSuffix to " for project \"" & theProjectName & "\","
else
set theProjectSuffix to ""
end if
end tell
-- Add the current task name and suffix to the task list text
set theTaskList to theTaskList & theCurrentTaskName & theProjectSuffix & return & return
end repeat
end tell
end repeat
end tell
end tell
end tell
-- Set the task list text to notify the user if not tasks were found.
if theTaskList = "" then
set theTaskList to "OmniFocus task review. There are currently no OmniFocus tasks in your \"" & thePerspectiveName & "\" perspective."
-- Add intro text to the task list text if tasks were found.
else
set theTaskList to "OmniFocus task review. The following OmniFocus tasks are in your \"" & thePerspectiveName & "\" perspective:" & return & return & theTaskList
end if
-- Set up the name and path for the audio task list file
set theAudioFileName to (date string of (current date)) & " OmniFocus " & thePerspectiveName & " Tasks.aif" as string
set theAudioFilePath to (path to desktop folder as string) & theAudioFileName
-- Save the task list text as audio
say theTaskList using "Alex" saving to theAudioFilePath
-- Return the path of the audio file
return POSIX path of theAudioFilePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment