Bullet Journaling with Drafts

Okay, let’s see if there’s anything I can add to this that’s of use :person_shrugging:t2:

Bullet Journalling Script in Drafts

Let’s try a slightly reworked version with a few tweaks in some of the logic, messages, and title matching.

// This is the same as "Go to Today's Journal", but I don't know how to define them in one place and share that information
let bjTitle = draft.processTemplate("# Journal for [[date|%A, %e %B %Y]]");
const tagsJournal = ["journal"];
const tags = draft.tags;
let draftJournal;

// If the current draft doesn't start with "-", "*", or "@", then add a "- " to the front of it, give it a second-level header 
// "##" and add a horizontal rule "---" beneath this section to visually distinguish each entry.
let currentContent = draft.content;
let strSeparator = "\n"
if ("-*@".indexOf(currentContent[0]) == -1) strSeparator = "\n\n- ";
currentContent = `- ## ${draft.processTemplate("[[created|%H:%M]]") + strSeparator + currentContent}\n\n---`;
// If the current draft doesn't end with a newline, then add one.
if (currentContent.slice(-1) != "\n") currentContent += "\n";

// Find matching drafts
let draftsMatching = Draft.queryByTitle(bjTitle, "all", tagsJournal);

// No match, create new journal
if (draftsMatching.length == 0)
{
	// Create the base journal
	draftJournal = Draft.create();
	draftJournal.content = bjTitle + "\n\n";
	// Add the bullet journal tags
	tagsJournal.forEach(function(strTag){draftJournal.addTag(strTag)});
	// Update and confirm
	draftJournal.update();
	app.displayInfoMessage("Created a new journal: " + bjTitle);
}

// Unique match, add to journal
if (draftsMatching.length == 1)
{
	// Abort if the draft we're trying to bullet journal is the day's bullet journal draft
	if (draft.uuid == draftsMatching[0].uuid) app.displayErrorMessage("Cannot self-bullet");
	// Not self-bulleting, so continue
	else
	{
		//Grab the matching draft and content
		draftJournal = draftsMatching[0];
	}
}

// Multiple matches, cannot proceed
if (draftsMatching.length > 1) app.displayErrorMessage(`Non-Unique Match: ${draftsMatching.length} drafts titled '${bjTitle}'`);
// We have a journal, let's populate with new content
else
{
	// Enforce end with a newline
	let contentWorking = draftJournal.content;
	if (contentWorking.slice(-1) != "\n") contentWorking += "\n";

	// Check each line for special characters, "-*@". 
	//If they are missing, prepend "- " to the line so it gets journaled.
	let newContent = "";
	let lines = currentContent.split("\n");
	lines.forEach(function(line)
	{
		if (line.length > 0)
		{
			if ("-*@".indexOf(line[0]) == -1)
			{
				line = "- " + line;
				newContent += line + "\n";
			}
			else newContent += line + "\n";
		}
		else newContent += line + "\n";
	});

	// Append the original draft content to the journal
	draftJournal.content = contentWorking + newContent;

	// Add the bullet journal tags
	tagsJournal.forEach(function(strTag){draftJournal.addTag(strTag)});
	draftJournal.update();
	app.displayInfoMessage(`Journaled draft ${draft.uuid}`);
}

My suspicion is that your monthly journal might contain the daily journal title somewhere in the body. but without having the data to check against it’s just guesswork.

Certainly I didn’t experience any particular issue with the first script, but the reworking might resolve it or perhaps help with narrowing down what is occurring.

Drafts to Obsidian

As Greg’s already noted, you can put your vault in the Drafts iCloud folder. But you’ll find that if you are using other apps to manage Obsidian on the go (e.g. 1Writer is probably the most popular choice), you may find that this limits this option.

If that is the case, you can utilise Shortcuts and Toolbox Pro or Scriptable to work around this. Toolbox Pro and Scriptable both support folder bookmarks, so you can export data from Drafts via these tools to other directories. On the Mac, you can utilise the TADpoLe draft function TA_exportOutsideMacSandbox() to save files outside of the Drafts folders.

Should you happen to be syncing to GitHub using the Obsidian Git plugin or equivalent, I recently released some functionality for working with GitHub in TADpoLe. There’s an accompanying blog post that explains how I have set it up, as I want to be able to capture in Drafts and push it off to Obsidian via GitHub for processing.

Hopefully some of the above will help.

2 Likes