HI @Andreas_Haberle, yeah absolutely!
The basic idea is that I want to have a global action that handles the creation of DayOne entries.
Every morning I start the day with a “morning pages” exercise where I clear my head and write down any tasks I need to do for the day. When I’m done writing, I have a Complete Morning Pages
action that marks the task complete in Streaks, creates a new draft from selected text, and sends all To-do’s to things. Once all of those steps have been completed the draft is passed off to the DayOne
action which files it away.
I could combine all of these actions into a single script but I’d like to keep the morning pages routine separate from the DayOne export. This not only makes my DayOne action reusable with other actions, but makes it easier to manage if I ever want to make changes to the way I export to DayOne.
Here is the code for the two related actions.
Action: Complete Morning Pages
Step 1: Script
// If running on an iPhone or iPad, open streaks.
const baseURL = "streaks://x-callback-url/completed/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
if (device.model != "Mac") { openCallback(baseURL); }
draft.setTemplateTag("journal","Morning Pages");
// Que actions to run
var actions = ["New from selection","Send To-do’s to things","DayOne"]
for (var i in actions) {
action = Action.find(actions[i]);
app.queueAction(action, draft);
}
Action: DayOne
Step 1: Script
var journals = [
"Journal",
"Morning Pages",
"Memories",
"Frisbee Scores"
];
var templateTag = "journal";
if (!draft.getTemplateTag(templateTag)) {
var p = Prompt.create();
p.title = "Choose A Journal";
p.message = "Which Journal would you like to use?";
p.addButton("OK");
p.addSelect(templateTag, "Journals", journals);
if (p.show()) {
draft.setTemplateTag(templateTag,p.fieldValues[templateTag]);
} else {
context.cancel();
}
}
Step 2: URL
dayone2://post?entry=[[draft]]&tags=[[tags]]&journal=[[journal]]
I like passing Template tags between scripts because it can drop right into the URL schema. I’ve been running it this way for months using the Include Action Step Type but I wanted to see if I could replicate this behavior with code.
Another possible solution could be to save the journey name as a tag or append it as text to the end of the draft. I don’t like those solutions as much because then I’m adding something to a draft only to remove it in the next action.
After some more testing, the code below works and sets a template tag for a queued action, but I have a feeling it might be more of a hack than an actual solution.
var d = Draft.find(draft.uuid);
var action = Action.find("DayOne");
d.setTemplateTag("journal","Morning Pages");
app.queueAction(action, d);