-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-selected-things3-projects-to-of3.applescript
170 lines (153 loc) · 5.62 KB
/
add-selected-things3-projects-to-of3.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
----------------------------------------------------
----------------------------------------------------
-- Import selected projects from Things to OmniFocus
----------------------------------------------------
----------------------------------------------------
--
-- Adapted from https://gist.github.com/matellis/69954d4212b1a36c13aad3de4e75187e by wkjarosz
-- Script taken from: http://forums.omnigroup.com/showthread.php?t=14846&page=2 && https://gist.github.com/cdzombak/11265615
--
-- Import just the selected projects in Things 3 to Omnifocus 3
--
-- Title of project for stuff in things with no project (avoids going into the Inbox)
--
property noProjectTitle : "No Project In Things"
tell application "Things3"
--
-- Import Projects into OF3
--
set projectList to {{missing value, noProjectTitle, "", "active", "", {}}}
set completedProjectList to {}
set AppleScript's text item delimiters to ","
set theProjects to selected to dos
repeat with aProject in theProjects
if class of aProject is project then
log name of aProject as string
log status of aProject as string
set areaName to null
if area of aProject is missing value then
set areaName to missing value
else
set areaName to name of area of aProject as string
end if
set projectName to name of aProject as string
set projectNotes to notes of aProject as string
-- set tagList to every text item of (tag names of aProject as string)
set tagList to my gatherTagsOf(aProject)
set projectCompletionDate to completion date of aProject
-- status: active/?on hold/?done/?dropped. vs open completed canceled
set projectStatus to status of aProject as string
copy {areaName, projectName, projectNotes, projectStatus, projectCompletionDate, tagList} to end of projectList
end if
end repeat
log "Processing " & (count of projectList) & " projects"
tell application "OmniFocus"
tell default document
repeat with aProject in projectList
set theFolderName to first item in aProject
set theProjectName to second item in aProject
set theProjectNotes to third item in aProject
set theProjectStatus to fourth item in aProject
set theProjectTags to sixth item in aProject
set theProjectCompletionDate to fifth item in aProject
if theFolderName is missing value then
-- no area
if (project theProjectName exists) then
set theProject to project theProjectName
else
set theProject to make new project with properties {name:theProjectName, note:theProjectNotes}
end if
if theProjectStatus is "completed" then
if not (my isItemInList(completedProjectList, theProject)) then
copy {theProject, theProjectCompletionDate} to end of completedProjectList
end if
end if
else
-- Project inside an area
tell folder theFolderName
if project theProjectName exists then
set theProject to project theProjectName
else
-- add tags
set theProject to make new project with properties {name:theProjectName, note:theProjectNotes}
end if
if theProjectStatus is "completed" then
if not (my isItemInList(completedProjectList, theProject)) then
copy {theProject, theProjectCompletionDate} to end of completedProjectList
end if
end if
end tell
move theProject to (end of sections of (first folder whose name is theFolderName))
end if
-- Write out tags
my writeTagsTo(theProject, theProjectTags)
end repeat
end tell
end tell
-- Mark complete any projects that should be that way
tell application "OmniFocus"
tell default document
repeat with completedProjectInfo in completedProjectList
set completedProject to first item of completedProjectInfo
set completedProjectDate to second item of completedProjectInfo
mark complete completedProject
set completion date of completedProject to completedProjectDate
end repeat
end tell
end tell
end tell -- Things application
-- Clumsy way of seeing if an item is in the Inbox as Things doesn't expose a "list" property
on isItemInList(theList, theItem)
set the matchFlag to false
repeat with anItem from 1 to the count of theList
if theList contains anItem then Â
set the matchFlag to true
end repeat
return the matchFlag
end isItemInList
-- Another hack for heirarchal tags to say "does tag exist inside this other tag?"
on isTagInList(theList, theItem)
set the matchFlag to false
repeat with anItem from 1 to the count of theList
if item anItem of theList is theItem then Â
set the matchFlag to true
end repeat
return the matchFlag
end isTagInList
-- less clumsy inbox hack
on isInInbox(anItem)
return ((area of anItem is missing value) and (project of anItem is missing value))
end isInInbox
-- gather tags
on gatherTagsOf(aTodo)
set allTagNames to {}
tell application "Things3"
repeat with aTag in every tag of aTodo
if (parent tag of aTag) is missing value then
copy {null, name of aTag} to end of allTagNames
else
copy {name of parent tag of aTag, name of aTag} to end of allTagNames
end if
end repeat
end tell
return allTagNames
end gatherTagsOf
-- write tags
on writeTagsTo(aTask, tagList)
tell application "OmniFocus"
tell default document
repeat with aTag in tagList
set theParentTag to first item of aTag
set theChildTag to second item of aTag
if theParentTag is null then
-- No Parent tag
add tag theChildTag to tags of aTask
else
-- Has a parent tag
set childTag to (first tag of tag theParentTag whose name is theChildTag)
add childTag to tags of aTask
end if
end repeat -- tags
end tell
end tell
end writeTagsTo