I’m using the action “Process Journal Items” from the Quick Journaling action group.
I made some modifications in order for it to support TickTick. When run from the Mac, it processes all the lines that are considered actions and uses the callback to add them to TickTick.
However, on the IOS devices it only processes the first one?
I suspect the issue is with my sendToTicktick function, but I’m confused why it would work on the Mac and not the IOS devices.
const lines = draft.content.split("\n");
const dayoneURL = "dayone2://post"
const fantasticalURL = "fantastical2://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";
// EZ - These constants are added for my purposes
const tags = draft.tags;
const title = draft.displayTitle;
const uuid = draft.uuid;
const ticktickURL = "ticktick://x-callback-url/v1/add_task?";
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;
cb.addParameter("sentence", entry);
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.open();
}
function sendToTodoist(entry) {
var cb = CallbackURL.create();
cb.baseURL = todoistURL;
cb.addParameter("content", entry);
cb.open();
}
// EZ - This function is meant to take only task list items and send them to TickTick via a callback URL
function sendToTicktick(entry) {
var cb = CallbackURL.create();
// EZ - Search for "- [x]" and replace it with a "X". I don't see that you can actually send TickTick a completed item. Hopefully that will change or I find a way.
if (entry.startsWith("[x]"||"[x] ") ) {
cb.addParameter("title", entry.replace(/\[x\]\s+/, 'X - ') );
}
// EZ - Search for "- [ ]" and clear it out. We don't need a checkbox in TickTick
else if (entry.startsWith("[ ]"||"[ ] ") ) {
cb.addParameter("title", entry.replace(/\[ \]\s+/, '') );
}
cb.baseURL = ticktickURL;
cb.addParameter("tags", tags);
cb.addParameter("content", "Generated from: " + "[" + title + "](drafts://x-callback-url/open?uuid=" + uuid + ")");
cb.waitForResponse = false;
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,
"TickTick": sendToTicktick,
}
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();
}