Last active
January 23, 2019 12:22
-
-
Save BrianHicks/40856beb7e851291e2d902eaad558016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env osascript -l JavaScript | |
ObjC.import('stdlib'); | |
function run(argv) { | |
area = argv.join(" "); | |
var things = Application("Things3"); | |
if (!things.running()) { | |
console.log("Things 3 is not running! Go start it and try me again."); | |
$.exit(1); | |
} | |
var projects = []; | |
for (var i = 0; i < things.projects.length; i++) { | |
projects.push(things.projects[i].name()); | |
} | |
var todos = []; | |
if (area === "") { | |
console.log("getting toDos from EVERYWHERE since there wasn't an area specified. This may take a while."); | |
toDos = things.toDos(); | |
} else { | |
try { | |
toDos = things.areas.byName(area).toDos(); | |
} catch(err) { | |
console.log("Does that area exist? Here was the error:"); | |
console.log(err); | |
$.exit(1); | |
} | |
} | |
var objects = []; | |
for (var i = 0; i < toDos.length; i++) { | |
toDo = toDos[i]; | |
objects.push({ | |
id: toDo.id(), | |
name: toDo.name(), | |
creationDate: toDo.creationDate(), | |
modificationDate: toDo.modificationDate(), | |
dueDate: toDo.dueDate(), | |
activationDate: toDo.activationDate(), | |
completionDate: toDo.completionDate(), | |
cancellationDate: toDo.cancellationDate(), | |
status: toDo.status(), | |
tagNames: toDo.tagNames(), | |
notes: toDo.notes(), | |
project: (toDo.project() ? toDo.project().name() : null), | |
area: (toDo.area() ? toDo.area().name() : null), | |
contact: (toDo.contact() ? toDo.contact().name() : null), | |
isProject: projects.indexOf(toDo.name()) !== -1 | |
}); | |
} | |
return JSON.stringify(objects); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment