Hi every body,
I've been playing around Omnifocus for a while now, reading and reading again
GTD book and even listening to the 8 (nearly 9) Hours of GTD Live 2 times.
And I got to the conclusion that i will not get GTD unless i was forced to ask me the questions David Allen is asking each time he is processing something.... (you know the kind of martial discipline unless you cannot apply GTD in the right way ;))
the fruit of this reflexions is a script that process my inbox items (those i've selected) and it asks the following questions :
what is the outcome of this item? (get the answer in the task's note)
is it actionnable? (yes or no) if no you've got the choice trash or someday/Maybe) trash delete the task; someday/maybe transform the task into a project in my folder "someday/maybe Projects" folder
does it require more than 1 action?-if yes it creates a project with the outcome as note in a folder named "to mindmap" (i use Xmind to "natural plan" my project and then use the excellent script
here to transcript it in omnifocus)
-if no it asks the questions
does it take more than 2 min? )> yes pops up a do it! display dialog
if no
it asks which existing project you want to assign the item
then
are you the right person to do it ?
(if no it assign the task to context "waiting")
if yes then it ask
which context is required to do the task
and then it ask
if it is time specific (if yes it tags the task "time specific" to get it in a specific perspective)
and off course it ask
how much time i need to do the task (if the answer is 180 the script propose to transform my task into project as over 2hours I can't get fully involved in only one task :p)
my script is not perfect => too much time when loading the data from onmifocus (especially when it creates the list )
i you can help me to optimize my script if you find it helps to get "GTD" diciplined
Best regards (and awaiting a lot of critics....):rolleyes:
Code:
property showAlert : true --if true, will display success/failure alerts
property useGrowl : true --if true, will use Growl for success/failure alerts
property defaultSnooze : 1 --number of days to defer by default
property alertItemNum : ""
property alertDayNum : ""
-- property successTot : 0
property growlAppName : "Dan's Scripts"
property allNotifications : {"General", "Error"}
property enabledNotifications : {"General", "Error"}
property iconApplication : "OmniFocus.app"
property action : false
property projet : false
property theContextname : "@Home"
global contextnameList
global projectnameList
global projectidList
global contextidlist
--chargement des contexts dans contextnameList
tell application "OmniFocus"
set contextnameList to {}
set contextidlist to {}
set contextnameList to my onContexts(contexts of default document)
set contextidlist to my onidcontexts(contexts of default document)
end tell
on onContexts(contextList)
repeat with aContext in contextList
my onContext(aContext)
end repeat
return contextnameList
end onContexts
on onidcontexts(contextList)
repeat with aContext in contextList
my onidContext(aContext)
end repeat
return contextidlist
end onidcontexts
on onContext(aContext)
using terms from application "OmniFocus"
set contextName to name of aContext
set contextLocation to location of aContext
set contextnameList to contextnameList & contextName
my onContexts(contexts of aContext)
end using terms from
end onContext
on onidContext(aContext)
using terms from application "OmniFocus"
set contextid to id of aContext
set contextidlist to contextidlist & contextid
my onidcontexts(contexts of aContext)
end using terms from
end onidContext
--fin du chargement
--chargement des Projects dans projectnameList
set projectnameList to {}
set projectidList to {}
tell application "OmniFocus"
set lstSections to every section of first document
set projectnameList to my ListSections(lstSections, projectnameList, 0)
set projectidList to my TrueListSections(lstSections, projectidList, 0)
end tell
on ListSections(lstSections, strList, intDepth)
using terms from application "OmniFocus"
repeat with oSectn in lstSections
if class of oSectn is project then
-- PROJECT
if oSectn is not completed and status of oSectn is not dropped and status of oSectn is not on hold then
set decalage to ""
repeat intDepth times
set strList to strList
set decalage to decalage & tab
end repeat
set namelist to decalage & name of oSectn
set strList to strList & namelist
end if
else
-- FOLDER
if oSectn is not hidden then
set decalage to ""
repeat intDepth times
set strList to strList
set decalage to decalage & tab
end repeat
set namelist to decalage & "folder" & name of oSectn
set strList to strList & namelist
-- ANY CONTENTS OF FOLDER
set lstSubSections to every section of oSectn
if lstSubSections ≠ {} then
set strList to my ListSections(lstSubSections, strList, intDepth + 1)
end if
end if
end if
end repeat
end using terms from
return strList
end ListSections
on TrueListSections(lstSections, strList, intDepth)
using terms from application "OmniFocus"
repeat with oSectn in lstSections
if class of oSectn is project then
-- PROJECT
if oSectn is not completed and status of oSectn is not dropped and status of oSectn is not on hold then
set decalage to ""
repeat intDepth times
set strList to strList
end repeat
set idlist to id of oSectn
set strList to strList & idlist
end if
else
-- FOLDER
if oSectn is not hidden then
repeat intDepth times
set strList to strList
end repeat
set idlist to id of oSectn
set strList to strList & idlist
-- ANY CONTENTS OF FOLDER
set lstSubSections to every section of oSectn
if lstSubSections ≠ {} then
set strList to my TrueListSections(lstSubSections, strList, intDepth + 1)
end if
end if
end if
end repeat
end using terms from
return strList
end TrueListSections
--fin du chargement
tell application "OmniFocus"
tell front document
tell (first document window whose index is 1)
set theSelectedItems to selected trees of content
set numItems to (count items of theSelectedItems)
if numItems is 0 then
set alertName to "Error"
set alertTitle to "Script failure"
set alertText to "No valid task(s) selected"
my notify(alertName, alertTitle, alertText)
return
end if
set selectNum to numItems
repeat while selectNum > 0
set Selectedtask to value of item selectNum of theSelectedItems
my Process(Selectedtask)
set selectNum to selectNum - 1
end repeat
end tell
end tell
end tell
on Process(Selectedtask)
--recuperation des infos de la tache
tell application "OmniFocus"
set taskName to name of Selectedtask
set taskNote to note of Selectedtask as rich text
end tell
--end recuperation des infos de la tache
--add outcome to the task
set question1 to display dialog taskName & return & "what is the outcome?" & return & "(ie describe the finished state)" default answer "" buttons {"OK", "Cancel"} default button 1
set outcome to (the text returned of the result) as text
if outcome is not "" then
tell application "OmniFocus"
set note of Selectedtask to taskNote & return & outcome
end tell
end if
--end of addition
-- set if it is actionnable or not
set question2 to display dialog "is it actionnable?" buttons {"yes", "no"} default button 1
set answer2 to button returned of question2
if answer2 is "yes" then
--set if it is a project
set question3 to display dialog "does it require more than 1 action?" buttons {"yes", "no"} default button 2
set answer3 to button returned of question3
if answer3 is "yes" then
my project(Selectedtask, "To mindmap")
-- end of the loop if it is a project
else
--set if it takes more than 2 min
set question4 to display dialog "will it take more than 2 minutes?" buttons {"yes", "no"} default button 1
set answer4 to button returned of question4
if answer4 is "no" then
set timer to display dialog "Do It!" buttons {"OK"} with icon caution giving up after 120
set overtime to gave up of timer
if overtime is equal to true then
set timer2 to display dialog "your 2 minutes are over click once you've finished your task" buttons {"OK"}
end if
tell application "OmniFocus"
tell front document
set completed of Selectedtask to true
set estimated minutes of Selectedtask to 2
set theContext to context "@Home"
set context of Selectedtask to theContext
compact
end tell
end tell
-- end of the loop if it took < 2min
else
-- the task takes more than 2 min so we difne its parameters
my definetask(Selectedtask)
end if
--end of determining if it takes more than 2min
end if
-- end of determinig it is a project or not
else
set mylist to {"trash", "someday/maybe"}
set choix to choose from list mylist with prompt "choose what to do"
if choix is {"trash"} then
tell application "OmniFocus"
delete Selectedtask
end tell
end if
if choix is {"someday/maybe"} then
my project(Selectedtask, "Someday/Maybe Projects")
end if
end if
end Process
on definetask(Selectedtask)
set projectName to choose from list projectnameList with prompt "affect a project to this action" as text
set question1 to display dialog "are you the right person to do it?" buttons {"yes", "no"} default button 1
set answer1 to button returned of question1
if answer1 is "no" then
set contextName to "Waiting"
tell application "OmniFocus"
tell front document
set n to count projectnameList
set test to (item n of projectnameList) as rich text
repeat while n > 0
set test to (item n of projectnameList) as rich text
ignoring white space
if projectName contains test then
set refindex to n
end if
end ignoring
set n to n - 1
end repeat
set idproject to (item refindex of projectidList) as rich text
set taskNote to note of Selectedtask
using terms from application "OmniFocus"
set theProject to project id idproject
end using terms from
set assigned container of Selectedtask to theProject
set context of Selectedtask to context contextName
end tell
end tell
else
set contextName to choose from list contextnameList with prompt "affect a context to this action " as text
set n to count projectnameList
set m to count contextnameList
set test to (item n of projectnameList) as text
set test2 to (item m of contextnameList) as text
repeat while n > 0
set test to (item n of projectnameList) as text
ignoring white space
if projectName contains test then
set refindex to n
end if
end ignoring
set n to n - 1
end repeat
repeat while m > 0
set test2 to (item m of contextnameList) as text
ignoring white space
if contextName contains test2 then
set refindex2 to m
end if
end ignoring
set m to m - 1
end repeat
set idproject to (item refindex of projectidList) as text
set idName to (item refindex of contextidlist) as text
set question2 to display dialog "is it time specific?" buttons {"yes", "no"} default button 2
set answer2 to button returned of question2
if answer2 is "yes" then
set comment to "time specific"
else
set comment to ""
end if
set mytimelist to {5, 10, 20, 30, 45, 60, 90, 120, 180}
set estimatedtime to choose from list mytimelist with prompt "how many minutes will it take"
considering numeric strings
if estimatedtime is equal to 180 then
set Alert to display dialog "this action will takes more than 2 hours,it is probably a GTD project, you should refine it" buttons {"OK", "Cancel"} default button 1
set agreement to button returned of Alert
if agreement is "OK" then
my project(Selectedtask, "To mindmap")
end if
else
tell application "OmniFocus"
tell front document
set taskNote to note of Selectedtask
using terms from application "OmniFocus"
set theProject to project id idproject
set theContext to context id idName
end using terms from
set assigned container of Selectedtask to theProject
set context of Selectedtask to theContext
set note of Selectedtask to taskNote & return & comment
set estimated minutes of Selectedtask to estimatedtime
compact
end tell
end tell
end if
end considering
end if
end definetask
on project(Selectedtask, locationname)
tell application "OmniFocus"
tell front document
using terms from application "OmniFocus"
set myfolder to a reference to folder locationname
set noteproject to note of Selectedtask as rich text
make new project at end of myfolder with properties {name:name of Selectedtask, note:noteproject}
delete Selectedtask
end using terms from
end tell
end tell
end project
Lionel