TIP: Journaling in Drafts

Drafts comes with a number of example actions to journal by appending to files in Dropbox, iCloud Drive and other locations. This tip is about how to journal to other drafts with Drafts.

All of these examples are based on the idea you want to launch Drafts, type a quick journal entry, and tap an action to append that entry to a running journal for the month, and have the action automatically roll over and create new journals for each month as you go. These examples are starting points and can be customize if you prefer to have daily journals, or weekly journals. See customization notes later in this tip.

Try the Monthly Journal Action

Hop over to the action directory and install the Monthly Journal example action.

  • Open drafts and “This is my journal entry” in a new draft.
  • Run the “Monthly Journal” action.

A few things will happen when you do this:

  • A new draft will be created for the current month, with a title like “# 2019-11: Monthly Journal”, assigned the tag “journal”.
  • The text of your current draft, along with a timestamp, will be appended the the end of that new draft.
  • Your current draft will be moved to the archive (using the after success option).

Go look in the inbox and you will find a new draft with the text (with different dates and times, of course):

# 2019-11: Monthly Journal

#### 01 November 2019 03:13 PM

This is my journal entry

Now, create another new draft, and type “Another journal entry” and run the action. The second time you run it, the action will find the existing monthly journal entry, and append the text. So if you go look at that entry again, it will now have the text:

# 2019-11: Monthly Journal

#### 01 November 2019 03:13 PM

This is my journal entry

#### 01 November 2019 03:35 PM

Another journal entry

Each time you use the action in the same month, it will append to the journal. When a new month comes around, it will create a new entry for that month.

Create a Journal Workspace

If you plan to journal in drafts with this action, or a modified version it, it is very useful to setup a Workspace that will allow you to easily filter the drafts list to show only your journal entries.

The docs show options and configuration, but since this action assigns the tag “journal” automatically to each journal it creates, the workspace needs only have a tag filter of journal.

Customizing the Action

This examples is configured as described, but can be altered easily to meet your needs. There are two script steps in the action. The first contains only a set of configuration variable which control the naming conventions for the title of the journal drafts, how the content is appended, the tag that is assigned to journals, etc. There are comments explaining the usage in the script step. The content variables are run through the Drafts template engine, so alterations can be made to the template tags to alter date formats, etc. If you are just getting started with templates, this Using Templates article is a great introduction.

5 Likes

This is so cool! I did have a question:

It seems that the archiving afterwards isn’t quite working. I tried switching the flag in the script to true, and that archived the full journal, not the individual journal entry.

Am I misunderstanding?

If you want the original action to archive the entry after running, you would only need to set the “After Success” setting for the action to “Archive”, not make any changes to the script.

Without seeing your script changes, I would assume you altered the d variable, which refers to the draft that contains the full journal.

1 Like

I love this. Thank you. I was using a Drobox journal through Drafts but prefer this one. However I would like the option to prepend rather than append the entries. Can this be easily done with this set up?
-rg

Ok, gotcha! I just saw that you said that was built into the script:

…so I didn’t realize I needed to edit.

Thank you!

Hello,

I’ve been trying to edit the script so it produces a weekly document. I can’t get the strftime.com page to give me a ‘date of the last Monday or today if it’s Monday’. Is there a way of making it do that?
Thanks!

strftime is a tool to format a date. It cannot adjust a date’s value to a different date/time, just turn it into a string. You would have to script adjusting the date, then use strftime to format it afterwards.

In the context of this action, in the first script step, where the title is generated, you could do something like this:

// get today's date
let d = Date.today()
// check if the day of the week is Monday (1), if not, move the date back
if (d.getDay() != 1) { 
	d = d.last().monday()
}
// convert the date to a string in the format you want
let dStr = strftime(d, "%Y-%m-%d") 
// use this new date string creating the title
let titleTemplate = `# ${dStr}: Monthly Journal`

Thanks for your help. Please can I check where to paste your code? I’ve added it here, but it’s returning an error message ‘Script Error: SyntaxError: Can’t create duplicate variable: ‘d’
Line number: undefined, Column undefined.’

// Configuration Options

/*
Template to use as title for journal notes.
Uses Drafts template tags to for current date, altering
date format can control whether journals are daily, monthly, etc.

The default %Y/%B/%W will create monthly journals with titles
like # 2019-11-01 - Daily Journal
*/
// get today’s date
let d = Date.today()
// check if the day of the week is Monday (1), if not, move the date back
if (d.getDay() != 1) {
d = d.last().monday()
}
// convert the date to a string in the format you want
let dStr = strftime(d, “%Y-%m-%d”)
// use this new date string creating the title
let titleTemplate = # ${dStr}: Monthly Journal

You put it in the right place. I didn’t realize the d variable name was already in use in the script else, just use a different value. Try:

let d1 = Date.today()
// check if the day of the week is Monday (1), if not, move the date back
if (d1.getDay() != 1) { 
	d1 = d1.last().monday()
}
// convert the date to a string in the format you want
let dStr = strftime(d1, "%Y-%m-%d") 
// use this new date string creating the title
let titleTemplate = `# ${dStr}: Monthly Journal`
1 Like

That’s worked! Thanks so much for your help.