Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Created December 30, 2016 01:08
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 brandonpittman/528250eaa0866d75f506acb8070e105c to your computer and use it in GitHub Desktop.
Save brandonpittman/528250eaa0866d75f506acb8070e105c to your computer and use it in GitHub Desktop.
Create a book project with OmniFocus
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use O : script "omnifocus"
on main(argv)
tell application "OmniFocus"
tell default document
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set bookInfo to argv as text
set bookTitle to text items 1 thru -2 of argv as text
set chapterCount to (last text item of argv) as number
set book to make new project with properties {name:bookTitle, sequential:true, context:O's findContext("Book Reading")}
--tell book to set launchTask to make new task with properties {name:"Read " & bookTitle & " (Focus project)", flagged:true}
--tell O to deferDaily(launchTask)
--tell book to set readingTasks to make new task with properties {name:"Reading tasks", sequential:true}
tell book
repeat with chapter from 1 to chapterCount
make task with properties {name:("Read " & bookTitle & ": Chapter " & chapter as text)}
end repeat
end tell
set AppleScript's text item delimiters to saveTID
end tell
end tell
end main
on handle_string(argv)
main(argv)
end handle_string
on run {}
set bookInfo to text returned of (display dialog "What's the title of the book? (include number of chapters at the end)" default answer "")
main(bookInfo)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment