I have a problem. I like to organize my grocery list in the order of the store layout. If the list is random, I push my cart around in a brownian-motion and it takes me too long to get out of the store.
When I saw the line-arrange function in drafts, I thought all my problems were solved. I dictate the list in drafts and re-arrange it in the right order and voila. But there was not an easy way to check off the items…
I wanted to use Omnifocus on my watch, because like I said in the beginning, I have a problem.
So I went to @RosemaryOrchard 's excellent TaskPaper to OF script which is a swiss-army knife of fucntions, and basically pulled out the cork screw for single-job use.
The action is just a single Script:
// convert drafts to a perfectly ordered
// OmniFocus Grocery List using Taskpaper formatted note.
// Get editor text and re-order for the grocery store layout.
var list = editor.getText();
var order = editor.arrange(list);
// add a tab & dash before every non-blank to make it a task under the project name.
var text = "";
var tasks = order.split("\n");
for (i in tasks) {
if (tasks[i].length !=0)
{
text += " - " + tasks[i] + "\n";
editor.setText(text);
};
}
// set project title to date + grocery list
var d = new Date();
var isoDate = d.toISOString().slice(0,10);
editor.setTextInRange(0,0, "-" + isoDate + " Grocery List: @autodone(true) @due(6h) @tags(@Errands)\n")
// This removes the project once all list items are checked off.
// Gives it an errands tag. You can also give it a specific location for a geotag.
// I set due to 6 hours so it shows up in my "due soon" list on my phone and watch.
// convert to Omnifocus tasks
// send this to OmniFocus
var cb = CallbackURL.create();
const baseURL = "omnifocus:///paste";
var target = "projects"; // <---You can place it in a subfolder here.
var draftsContent = editor.getText();
cb.baseURL = baseURL;
cb.addParameter("target", target);
cb.addParameter("content", draftsContent);
// open and wait for result
var success = cb.open();
if (success) {
console.log("Taskpaper added to OF");
}
else { // something went wrong
console.log(cb.status);
context.fail();
}