API questions (requests?) for implementing a pomodoro script


#1

TL;DR: lots of questions about building a pomodoro script in TaskPaper. Mostly: is there a way to have timers and notifications?

I wrote a pomodoro script for TaskPaper but I don’t like how hacky it is. I have started writing a v2 and have some API questions (or perhaps requests) as a result.

This is what I’d like to achieve:

  • External app (Alfred in this case) gets list of candidate items for next pomodoro. v1 does this fine. I did this externally but maybe getOutlineEditors() would have been better.
  • External app picks an Item and adds @pomo(<countdown>) to it in TaskPaper. I think that I know how to do this. Something like: item.setAttribute("data-pomo", 25);
  • But now comes the part that I don’t know how to do. I’d like to be able to register for timer callbacks and (1/minute) change the attribute. Down to 0.
  • And then the other part that I don’t see a way to do: I’d like to fire a notification when the timer hits 0?

Have I misread the docs and there is a way to do the countdown and notification steps? Or is there no such feature?


#2

Here’s a start I think:

function UpdateInTaskPaperContextScript(editor, options) {
	debugger
	editor.outline.evaluateItemPath('@pomo').forEach(function(each) {
		var value = each.getAttribute('data-pomo', Number)		
		each.setAttribute('data-pomo', value + 1)
	});
}

var taskPaper = Application('TaskPaper')
taskPaper.activate()
while (taskPaper.running()) {
	for (var i = 0; i < taskPaper.documents.length; i++) {
		taskPaper.documents[i].evaluate({
			script: UpdateInTaskPaperContextScript.toString()
		})
	}
	delay(5);
}

If you run this script then it should:

  1. Launch TaskPaper from AppleScript context
  2. Setup a loop in the AppleScript context that:
  • Checks if TaskPaper is still running
  • If it IS still running then runs the UpdateInTaskPaperContextScript function within TaskPaper. And that function searches for and increments @pomo tagged item values.
  • Delays for 5 seconds