Posted By

jchilders on 09/08/10


Tagged


Versions (?)

Import Todo's from Things into Omnifocus


 / Published in: AppleScript
 

  1. --------------------------------------------------
  2. --------------------------------------------------
  3. -- Import tasks from Things to OmniFocus
  4. --------------------------------------------------
  5. --------------------------------------------------
  6. tell application "Things"
  7.  
  8. -- Loop through ToDos in Things
  9. repeat with aToDo in to dos of list "Next"
  10.  
  11. -- Get title and notes of Things task
  12. set theTitle to name of aToDo
  13. set theNote to notes of aToDo
  14.  
  15. -- Get project name
  16. if (project of aToDo) is not missing value then
  17. set theProjectName to (name of project of aToDo)
  18. else if (area of aToDo) is not missing value then
  19. set theProjectName to (name of area of aToDo)
  20. else
  21. set theProjectName to "NoProjInThings"
  22. end if
  23.  
  24. -- Get Contexts from tags
  25. -- get all tags from one ToDo item...
  26. set allTagNames to {}
  27. copy (name of tags of aToDo) to allTagNames
  28. -- ...and from the project...
  29. if (project of aToDo) is not missing value then
  30. copy (name of tags of project of aToDo) to the end of allTagNames
  31. end if
  32. -- ...now extract contexts from tags
  33. copy my FindContextName(allTagNames) to theContextName
  34.  
  35. -- Create a new task in OmniFocus
  36. tell application "OmniFocus"
  37.  
  38. tell default document
  39.  
  40. -- Set (or create new) task context
  41. if context theContextName exists then
  42. set theContext to context theContextName
  43. else
  44. set theContext to make new context with properties {name:theContextName}
  45. end if
  46.  
  47. -- Set (or create new) project
  48. if project theProjectName exists then
  49. set theProject to project theProjectName
  50. else
  51. set theProject to make new project with properties {name:theProjectName}
  52. end if
  53.  
  54. -- Create new task
  55. tell theProject
  56. set newTask to make new task with properties {name:theTitle, note:theNote, containing project:theProject, context:theContext}
  57. end tell
  58.  
  59. end tell -- document
  60. end tell -- OF application
  61. end repeat -- Main loop
  62. end tell -- Things application
  63.  
  64.  
  65. --------------------------------------------------
  66. --------------------------------------------------
  67. -- Get context from array of Things tags
  68. --------------------------------------------------
  69. --------------------------------------------------
  70. on FindContextName(tagNames)
  71. -- Example usage
  72. --FindContextName("@Mac", "1/2hr", "High") -- FYI, my tags are context, duration and priority
  73.  
  74. repeat with aTagName in tagNames
  75. if aTagName starts with "@" then
  76. return aTagName
  77. end if
  78. end repeat
  79. return ""
  80.  
  81. end FindContextName -- End FindContextName
  82.  
  83.  
  84. --------------------------------------------------
  85. --------------------------------------------------
  86. -- Remove the CRs from a string,
  87. -- not used in this script,
  88. -- carry over from prior implementation
  89. --------------------------------------------------
  90. --------------------------------------------------
  91. on ReplaceText(find, replace, subject)
  92. -- Example usage
  93. -- ReplaceText("Windows", "the Mac OS", "I love Windows and I will always love Windows and I have always loved Windows.")
  94.  
  95. set prevTIDs to text item delimiters of AppleScript
  96. set text item delimiters of AppleScript to find
  97. set subject to text items of subject
  98.  
  99. set text item delimiters of AppleScript to replace
  100. set subject to "" & subject
  101. set text item delimiters of AppleScript to prevTIDs
  102.  
  103. return subject
  104.  
  105. end ReplaceText -- End replaceText()

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: egilDOTnet on October 9, 2010

Brilliant! Worked like a charm!

You need to login to post a comment.