Action
Process journal items
Process each line of the draft. By the default settings file:
- Lines starting with “-“ are collected and sent to Day One as a journal entry
- Lines starting with “*” are sent to OmniFocus’s inbox
- Lines starting with “@“ are sent to Fantastical
Everything else is ignored.
Version 1.3 by Kirk Strauser
Steps
-
script
var settingsTitle = "# Quick Journaling settings" var tag = "settings" var settingsDrafts = Draft.query(settingsTitle, "all", [tag]); if (settingsDrafts.length > 1) { app.displayErrorMessage("Found more than one settings file named '" + settingsTitle + "'"); context.fail(); } else { if (settingsDrafts.length == 0) { var ourSettings = Draft.create(); ourSettings.content = settingsTitle + "\n" + ` // These lines determine which action is taken for each line in your Today's Journal. @ Fantastical * OmniFocus - Day One // Line format: "<trigger character><space>Name Of App". // Lines that start with "//" or "#", or which are blank, are ignored. Feel free to add new mappings (e.g. "& GoodTask" if that's your thing) or delete ones you never want to use. // Supported apps: // // Day One // Fantastical // GoodTask // OmniFocus // Reminders // Things // Todoist `; ourSettings.addTag(tag); ourSettings.update(); app.displayInfoMessage("Created a new settings file: " + settingsTitle); } else { var ourSettings = settingsDrafts[0]; } var lineProcessors = {} for (var line of ourSettings.content.split("\n")) { line = line.trim(); if ( line.length == 0 || line[0] == "#" || line.substr(0, 2) == "//" ) { continue; } first = line[0]; rest = line.substr(1).trim(); if (rest.length == 0) { continue; } lineProcessors[first] = rest; } }
-
script
const lines = draft.content.split("\n"); const dayoneURL = "dayone2://post" let fantasticalURL = "x-fantastical3://parse"; if(device.model != "Mac"){ fantasticalURL = "x-fantastical3://x-callback-url/parse" } const goodtaskURL = "goodtask3://x-callback-url/add"; const omnifocusURL = "omnifocus://x-callback-url/add"; const thingsURL = "things:///add"; const todoistURL = "todoist://addtask"; var dayOneLines = []; // Actions for sending journal entries to various apps function collectForDayOne(entry) { dayOneLines.push(entry); } function sendToFantastical(entry) { var cb = CallbackURL.create(); cb.baseURL = fantasticalURL; if(device.model != "Mac"){ cb.addParameter("sentence", entry); } else { cb.addParameter("s", entry); } cb.waitForResponse = true cb.open(); } function sendToGoodTask(entry) { var cb = CallbackURL.create(); cb.baseURL = goodtaskURL; cb.addParameter("title", entry); cb.open(); } function sendToOmniFocus(entry) { var cb = CallbackURL.create(); cb.baseURL = omnifocusURL; cb.addParameter("name", entry); cb.open(); } function sendToReminders(entry) { var list = ReminderList.findOrCreate("Journal"); var reminder = list.createReminder(); reminder.title = entry; reminder.update(); } function sendToThings(entry) { var cb = CallbackURL.create(); cb.baseURL = thingsURL; cb.addParameter("title", entry); cb.waitForResponse = true cb.open(); } function sendToTodoist(entry) { var cb = CallbackURL.create(); cb.baseURL = todoistURL; cb.addParameter("content", entry); cb.open(); } // Resolve actions defined in the settings file to the actual // functions to call. var actionMap = { "Day One": collectForDayOne, "Fantastical": sendToFantastical, "GoodTask": sendToGoodTask, "OmniFocus": sendToOmniFocus, "Reminders": sendToReminders, "Things": sendToThings, "Todoist": sendToTodoist, } var actions = {} for (var key in lineProcessors) { var actionName = lineProcessors[key]; actions[key] = actionMap[actionName]; } // Process all the lines. for (var line of lines) { line = line.trim(); if (line.length == 0) { continue; } first = line[0]; rest = line.substr(1).trim(); if (rest.length == 0) { continue; } action = actions[first]; if (action === undefined) { continue; } action(rest); } // Some actions are processed in a batch after all their entries // are collected. This is where that happens. if (dayOneLines.length) { var body = dayOneLines.join("\n\n"); var cb = CallbackURL.create(); cb.baseURL = dayoneURL; cb.addParameter("entry", body); cb.waitForResponse = false; cb.open(); }
Options
-
After Success Trash Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.