Skip to content

Instantly share code, notes, and snippets.

@sbentzen
Created February 25, 2012 00:37
Show Gist options
  • Save sbentzen/1904907 to your computer and use it in GitHub Desktop.
Save sbentzen/1904907 to your computer and use it in GitHub Desktop.
Things to Things Migration
---------
-- Convert Things database to Things Beta database.
-- This script clones all area's, projects, people and tasks with all its relations, properties and correct ordering without any duplicates.
-- * 25 November 2011: Initial version.
-- * 26 November 2011: Removed some linefeeds to make it better readable on the forum.
-- * 27 November 2011: Fixed bug in addTask where activation was set in error.
--
-- TODO:
-- * Preserve log dates of completed tasks in the logbook. (I really want this, but think it isn't possible according to the current Things AppleScipt Guide?)
-- * Preserve repeating schedules. (I think this isn't possible either?)
-- * Preserve tag hierarchy. (I personally don't use parent-child relations for tags that much, so I didn't code it…)
--
-- KNOWN BUGS:
-- * In my setup, one single task that should only be in the Today list also ends up in the Inbox. I know why and how to fix it, but it would result in unreadable workaround code so I choose to simply edit this single task manually aftwerwards...
--
-- See: [culturedcode.com]
----------
tell application "Things beta"
empty trash
end tell
-- NOTE: If you have a big database, you may run these functions one by one as well...
createTemp() of me
cloneAreas() of me
cloneProjects() of me
clonePeople() of me -- NOTE: Only works when displaying the full name for each teammate.
cloneTasks() of me
cloneAreaTasks() of me
cloneScheduledTasks() of me
cloneList("Inbox") of me
cloneList("Today") of me
cloneList("Someday") of me
deleteTemp() of me
tell application "Things beta"
log completed now
empty trash
end tell
on createTemp()
log "At " & (current date) & ": Creating temp…"
tell application "Things beta"
set prName to "__TEMP__"
if not (exists to do prName in list "Projects") then make new project with properties {name:prName}
end tell
end createTemp
on deleteTemp()
log "At " & (current date) & ": Deleting temp…"
tell application "Things beta"
set tds to properties of every to do of project "__TEMP__"
repeat with td in tds
moveTaskToList(td, "Inbox") of me
end repeat
delete project "__TEMP__"
end tell
end deleteTemp
on cloneAreas()
log "At " & (current date) & ": Getting area's…"
tell application "Things"
set ars to properties of every area
repeat with ar in reverse of ars
addArea(ar) of me
end repeat
end tell
end cloneAreas
on cloneProjects()
log "At " & (current date) & ": Getting projects..."
tell application "Things"
set prs to properties of every project
repeat with pr in reverse of prs
addProject(pr) of me
end repeat
end tell
end cloneProjects
on clonePeople()
log "At " & (current date) & ": Getting people…"
tell application "Things"
set ppl to properties of every person
repeat with ps in reverse of ppl
addPerson(ps) of me
end repeat
end tell
end clonePeople
on addArea(ar)
tell application "Things beta"
set arName to name of ar
if exists area arName then return
log "At " & (current date) & ": Creating area '" & arName & "'..."
set newArea to make new area with properties {name:arName, suspended:suspended of ar, tag names:tag names of ar}
end tell
end addArea
on addProject(pr)
tell application "Things beta"
set prName to name of pr
if exists to do prName in list "Projects" then return
log "At " & (current date) & ": Creating project '" & prName & "'..."
---
set newProject to make new project with properties {name:prName, notes:notes of pr, status:status of pr, tag names:tag names of pr}
if due date of pr is not missing value then set due date of newProject to due date of pr
---
set prArea to area of pr
if prArea is not missing value then
set prAreaName to name of prArea
set area of newProject to area prAreaName
end if
end tell
end addProject
on addPerson(ps)
tell application "Things beta"
set psName to name of ps
if exists person psName then return
log "At " & (current date) & ": Creating person '" & psName & "'..."
add teammate named psName
end tell
end addPerson
on cloneTasks()
log "At " & (current date) & ": Getting tasks..."
tell application "Things"
set tds to properties of every to do
repeat with td in tds
addTask(td) of me
end repeat
end tell
end cloneTasks
on addTask(td)
tell application "Things beta"
set tdName to name of td
if exists to do tdName then return
log "At " & (current date) & ": Adding task '" & tdName & "'..."
---
set newTd to make new to do with properties {name:tdName} at beginning of project "__TEMP__"
---
set notes of newTd to notes of td
set status of newTd to status of td
set tag names of newTd to tag names of td
set creation date of newTd to creation date of td
set modification date of newTd to modification date of td
---
if due date of td is not missing value then set due date of newTd to due date of td
if completion date of td is not missing value then set completion date of newTd to completion date of td
if cancellation date of td is not missing value then set cancellation date of newTd to cancellation date of td
---
set tdProject to project of td
if not tdProject is missing value then
set tdProjectName to name of tdProject
set project of newTd to project tdProjectName
end if
---
-- NOTE: This does not preserve the order of tasks in area's, so I coded a separate cloneAreaTasks() instead.
--set tdArea to area of td
--if tdArea is not missing value then
-- set tdAreaName to name of tdArea
-- set area of newTd to area tdAreaName
--end if
---
set tdPerson to delegate of td
if tdPerson is not missing value then
set tdPerson2 to person named (name of tdPerson)
set delegate of newTd to tdPerson2
end if
end tell
end addTask
on cloneAreaTasks()
log "At " & (current date) & ": Cloning area tasks…"
tell application "Things"
set ars to properties of every area
repeat with ar in ars
set arName to name of ar
set tds to properties of every to do of area arName
repeat with td in reverse of tds
moveTaskToArea(td, arName) of me
end repeat
end repeat
end tell
end cloneAreaTasks
on moveTaskToArea(td, ar)
tell application "Things beta"
set tdName to name of td
if exists to do tdName in area ar then return
log "At " & (current date) & ": Moving task '" & tdName & "' to area '" & ar & "'…"
set td2 to to do tdName
move td2 to area ar
end tell
end moveTaskToArea
on cloneScheduledTasks()
log "At " & (current date) & ": Cloning scheduled tasks…"
tell application "Things"
set tds to properties of every to do of list "Scheduled"
repeat with td in reverse of tds
moveTaskToScheduled(td) of me
end repeat
end tell
end cloneScheduledTasks
on moveTaskToScheduled(td)
tell application "Things beta"
set tdName to name of td
if exists to do tdName in list "Scheduled" then return
log "At " & (current date) & ": Scheduling task '" & tdName & "'…"
set td2 to to do tdName
schedule td2 for (activation date of td)
end tell
end moveTaskToScheduled
on cloneList(tdList)
log "At " & (current date) & ": Cloning list tasks…"
tell application "Things"
set tds to properties of every to do of list tdList
repeat with td in reverse of tds
moveTaskToList(td, tdList) of me
end repeat
end tell
end cloneList
on moveTaskToList(td, tdList)
tell application "Things beta"
set tdName to name of td
if exists to do tdName in list tdList then return
log "At " & (current date) & ": Moving task '" & tdName & "' to list '" & tdList & "'…"
set td2 to to do tdName
move td2 to list tdList
end tell
end moveTaskToList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment