Skip to content

Instantly share code, notes, and snippets.

@wakatara
Created February 27, 2013 04:38
Show Gist options
  • Save wakatara/5045124 to your computer and use it in GitHub Desktop.
Save wakatara/5045124 to your computer and use it in GitHub Desktop.
A Applescript to migrate all tasks out of Cultured Code's THings for OSX and put them in the proper text format for Taskpaper from Hog's Bay Software.
-- modified on 21 Feb 2013 by Daryl Manning
set thePath to (path to desktop as Unicode text) & "Things2Taskpaper.taskpaper"
set thingsToDoFile to (open for access file thePath with write permission)
set eof of thingsToDoFile to 0
set cr to ASCII character 10
tell application "Things"
-- Export to-dos from Inbox
write "Inbox:" & return to thingsToDoFile as «class utf8»
repeat with td in to dos of list "Inbox"
set tdName to the name of td
set tdNotes to the notes of td
set tdDueDate to the due date of td
set tdCompletionDate to the completion date of td
set tdTagNames to the tag names of td
write tab & "- " & tdName to thingsToDoFile as «class utf8»
if tdDueDate is not missing value then
set tdGoodDueDate to my tpDate(tdDueDate)
write " @due(" & tdGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if tdCompletionDate is not missing value then
set tdCompletionDate to my tpDate(tdCompletionDate)
write " @done(" & tdCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
if tdTagNames is not missing value then
repeat with tdTag in (words of tdTagNames)
write " @" & tdTag to thingsToDoFile as «class utf8»
end repeat
end if
write return to thingsToDoFile as «class utf8»
if tdNotes is not "" then
set fixedNote to my replaceText(cr, "; ", tdNotes)
write tab & tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
end repeat
write return to thingsToDoFile as «class utf8»
write "Scheduled:" & return to thingsToDoFile as «class utf8»
repeat with td in to dos of list "Scheduled"
set tdName to the name of td
set tdNotes to the notes of td
set tdDueDate to the due date of td
set tdCompletionDate to the completion date of td
set tdTagNames to the tag names of td
write tab & "- " & tdName to thingsToDoFile as «class utf8»
if tdDueDate is not missing value then
set tdGoodDueDate to my tpDate(tdDueDate)
write " @due(" & tdGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if tdCompletionDate is not missing value then
set tdCompletionDate to my tpDate(tdCompletionDate)
write " @done(" & tdCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
if tdTagNames is not missing value then
repeat with tdTag in (words of tdTagNames)
write " @" & tdTag to thingsToDoFile as «class utf8»
end repeat
end if
write return to thingsToDoFile as «class utf8»
if tdNotes is not "" then
set fixedNote to my replaceText(cr, "; ", tdNotes)
write tab & tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
end repeat
write return to thingsToDoFile as «class utf8»
-- Walk through projects, export as project with their to-dos
repeat with pr in to dos of list "Projects"
set prName to the name of pr
set prNotes to the notes of pr
set prDueDate to the due date of pr
set prCompletionDate to the completion date of pr
write prName & ":" & return to thingsToDoFile as «class utf8»
if prDueDate is not missing value then
set prGoodDueDate to my tpDate(prDueDate)
write " @due(" & prGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if prCompletionDate is not missing value then
set prCompletionDate to my tpDate(prCompletionDate)
write " @done(" & prCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
write return to thingsToDoFile as «class utf8»
if prNotes is not "" then
set fixedNote to my replaceText(cr, "; ", prNotes)
write tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
repeat with td in to dos of project prName
set tdName to the name of td
set tdNotes to the notes of td
set tdDueDate to the due date of td
set tdCompletionDate to the completion date of td
set tdTagNames to the tag names of td
write tab & "- " & tdName to thingsToDoFile as «class utf8»
if tdDueDate is not missing value then
set tdGoodDueDate to my tpDate(tdDueDate)
write " @due(" & tdGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if tdCompletionDate is not missing value then
set tdCompletionDate to my tpDate(tdCompletionDate)
write " @done(" & tdCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
if tdTagNames is not missing value then
repeat with tdTag in (words of tdTagNames)
write " @" & tdTag to thingsToDoFile as «class utf8»
end repeat
end if
write return to thingsToDoFile as «class utf8»
if tdNotes is not "" then
set fixedNote to my replaceText(cr, "; ", tdNotes)
write tab & tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
end repeat
write return to thingsToDoFile as «class utf8»
end repeat
-- Walk through areas, export as project with their to-dos
repeat with ar in areas
set arName to the name of ar
write arName & ":" & return to thingsToDoFile as «class utf8»
repeat with td in to dos of ar
set tdName to the name of td
set tdNotes to the notes of td
set tdDueDate to the due date of td
set tdCompletionDate to the completion date of td
set tdTagNames to the tag names of td
write tab & "- " & tdName to thingsToDoFile as «class utf8»
if tdDueDate is not missing value then
set tdGoodDueDate to my tpDate(tdDueDate)
write " @due(" & tdGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if tdCompletionDate is not missing value then
set tdCompletionDate to my tpDate(tdCompletionDate)
write " @done(" & tdCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
if tdTagNames is not missing value then
repeat with tdTag in (words of tdTagNames)
write " @" & tdTag to thingsToDoFile as «class utf8»
end repeat
end if
write return to thingsToDoFile as «class utf8»
if tdNotes is not "" then
set fixedNote to my replaceText(cr, "; ", tdNotes)
write tab & tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
end repeat
write return to thingsToDoFile as «class utf8»
end repeat
-- Export to-dos from Someday
write "Someday:" & return to thingsToDoFile as «class utf8»
repeat with td in to dos of list "Someday"
set tdName to the name of td
set tdNotes to the notes of td
set tdDueDate to the due date of td
set tdCompletionDate to the completion date of td
set tdTagNames to the tag names of td
write tab & "- " & tdName to thingsToDoFile as «class utf8»
if tdDueDate is not missing value then
set tdGoodDueDate to my tpDate(tdDueDate)
write " @due(" & tdGoodDueDate & ")" to thingsToDoFile as «class utf8»
end if
if tdCompletionDate is not missing value then
set tdCompletionDate to my tpDate(tdCompletionDate)
write " @done(" & tdCompletionDate & ")" to thingsToDoFile as «class utf8»
end if
if tdTagNames is not missing value then
repeat with tdTag in (words of tdTagNames)
write " @" & tdTag to thingsToDoFile as «class utf8»
end repeat
end if
write return to thingsToDoFile as «class utf8»
if tdNotes is not "" then
set fixedNote to my replaceText(cr, "; ", tdNotes)
write tab & tab & fixedNote & return to thingsToDoFile as «class utf8»
end if
end repeat
write return to thingsToDoFile as «class utf8»
close access thingsToDoFile
end tell
on replaceText(find, replace, someText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to "" & someText
set text item delimiters of AppleScript to prevTIDs
return someText
end replaceText
on tpDate(mydate)
set y to text -4 thru -1 of ("0000" & (year of mydate))
set m to text -2 thru -1 of ("00" & ((month of mydate) as integer))
set d to text -2 thru -1 of ("00" & (day of mydate))
return y & "-" & m & "-" & d
end tpDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment