My silly widget: A new take on a Grocery List Script in Drafts

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";

// 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 =;
if (success) {
	console.log("Taskpaper added to OF");
else { // something went wrong

I use Grocery which syncs with a Reminders list. Grocery is intelligent and sort the shopping list according to store layout (learns by the order you check off items). And you can create multiple stores.

The Reminders list sync is brilliant since I can then use whatever trick in the book to populate it.