Last active
May 1, 2019 15:00
-
-
Save brandonpittman/aefa37b56a35f4affc3148585247fc5f to your computer and use it in GitHub Desktop.
Things OpenAndComplete written in JS (v2)
This file contains 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
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