Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Things OpenAndComplete written in JS (v2)
function run(argv) {
var app = Application('Things3')
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
var selected = app.selectedToDos()
if (selected.length !== 0) {
selected.forEach(todo => {
todo.completionDate = new Date()
if (todo.notes().length > 0) {
let notes = todo.notes().split('\n')
notes.forEach(line => {
handleLine(line)
})
} else {
currentApp.displayNotification(`"${todo.name()}" doesn't have any notes.`)
}
})
} else {
currentApp.displayNotification(`You haven't selected any tasks.`)
}
}
function trimLine(line, key) { return line.slice(key.length).trim() }
function sanitizeLine(line) { return line.replace(/'/g, "") }
function handleLine(line) {
var app = Application('Things3')
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
var line = sanitizeLine(line)
if (line.includes('://')) {
currentApp.doShellScript(`open '${line}'`)
} else if (line.startsWith('scpt:')) {
var script = trimLine(line, 'scpt:')
currentApp.doShellScript(`osascript '${script}'`)
} else if (line.startsWith('sh:')) {
var script = trimLine(line, 'sh:')
currentApp.doShellScript(`'${script}'`)
} else if (line.startsWith('template:')) {
var path = trimLine(line, 'template:')
var template = currentApp.read(Path(path))
var lines = template.split("\n")
lines.forEach(line => handleLine(line))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment