Script to implement "Autofocus" system

Use this script to implement a version of Mark Forster’s Autofocus time management system.

tell application "FoldingText"
	tell front document
		evaluate script "function(editor, options) {
            var tree = editor.tree(),
                item = editor.selectedRange().startNode,
                itemPage = item.parent;

            while (itemPage && itemPage.text() !== 'Autofocus') {
                itemPage = itemPage.parent;
            }

            if (itemPage) {
                var pagesParent = itemPage.parent,
                    lastPage = pagesParent.lastChild,
                    reenterItem = tree.createNode(item.line());

                tree.beginUpdates();                
                if (lastPage === itemPage || lastPage.children().length > 30) {
                    lastPage = tree.createNode('# Autofocus.todo');
                    pagesParent.appendChild(tree.createNode());
                    pagesParent.appendChild(lastPage);
                    lastPage.appendChild(tree.createNode());
                }
                lastPage.appendChild(reenterItem);
                item.addTag('done', new Date().toISOString().substr(0, 10));
                tree.endUpdates();
            }
        }" with options {}
	end tell
end tell

Watch this (dated, but function still same) screencast to see how to use this script.

The autofocus system is paper based, but it can be implemented on the computer by using a new heading for each page. To try out the script first create a new document and paste in the following text:

# Autofocus.todo

- item 1
- item 3

# Autofocus.todo

- item 2

Then place your cursor on one of the todo items and run the script. The item will be marked “done” and then reentered on on the last page.

In this implementation an Autofocus.todo heading is created for each page. Use unordered list syntax for items so that you can get a nice clickable checkbox to cross the items off the list. The process is the same as described on Mark’s page, except:

  1. Instead of using physical pages add your items to “Autofocus.todo” headings.

  2. Instead of physically crossing items of your lists, click the checkbox that’s added by .todo mode. That will add the @done tag to the item so that it gets visually crossed off.

  3. Instead of manually re-entering items that you are not finished with, place your text cursor on the items line, and run the linked to “Re-Enter” script. That will move a copy of the item to the end of your list. And it will automatically create “Autofocus.todo” headings as needed.

Update

  • This script now adds date value along with “done” tag.

Update 2

  • Fixed to work with latest FoldingText

I’m pasting, compiling, and running. No joy. I receive a “null” message. Complete noob re AppleScript. Any recommendations to successfully install would be most appreciated.

Are you creating a new document as pasting in the example text in those post before running the script? The script does end up with a “null” result by default, so that doesn’t necessarily indicate a problem.

Hey Jesse. I’m getting the following error message from the Apple script. What am I doing wrong?

"TypeError: new Date().format is not a function. (In 'new Date().format('isoDate')', 'new Date().format' is undefined)
	Use the Help > SDKRunner to debug"

Opps some internals changed and broke that. I’ve just updated the script to work with the latest FoldingText.