Action

open daily journal

Posted by FlohGro, Last update 12 days ago

created by @FlohGro / more on my Blog

open daily journal

This Action opens a journaling Draft for the current date with a configurable date format for the title and content of the Draft.
If the todays Draft is already existing the action will open it.

[Configuration]

Before you can use the action you need to configure it depending on your setup in Drafts and personal preference.

The configuration parameters are adapted in the „Define Template Tag“ steps in the Action. To change the configurations edit them to match your setup - don’t change the names of the template tags since the action won’t work anymore afterwards. The following parameters must be adapted:

  • dateFormat: the format of the date in the title of the journaling draft. You need to use the Drafts specific notation documented here. Default: %a %Y-%m-%d which results in titles like „Wed 2022-11-16“
  • draftTitleSuffix: the suffix that will be appended after the configured date format in the title. Default: - Journal which creates titles like „Wed 2022-11-16 - Journal“
  • templateContent: the optional template body for the Draft. The best way to configure it would be to format the template to your preference in a draft and copy the content to the Define Template Tag step. You can e.g. predefine some sections for your Daily Journal note in this template. Default: empty
  • workspaceName: the name of the workspace for your daily notes that you use. If you don‘t use a specific workspace to filter for the Daily Notes you can leave it empty. Default: empty
  • pinOnSuccess: if the created / opened daily note journal draft shall be pinned when the action ran successfully. Default: true (anything except true will not enable the pinning mode)

If you want to add specific tags to the daily journaling drafts to e.g. add the daily journaling drafts into a specific workspace please make use of the standard „AFTER SUCCESS“ settings in the action. You can e.g. archive the draft there and set tags that shall be assigned when the draft is created / opened.

[Usage]

Use this action to quickly open a journaling draft for the current day. If you want to have even quicker access you can start a live activity for the created draft or add the action as a widget on the Lockscreen.


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • defineTemplateTag

    name
    dateFormat
    template
    %a %Y-%m-%d
  • defineTemplateTag

    name
    draftTitleSuffix
    template
    - Journal
  • defineTemplateTag

    name
    templateContent
    template
  • defineTemplateTag

    name
    workspaceName
    template
  • defineTemplateTag

    name
    pinOnSuccess
    template
    true
  • script

    // open todays journal Note
    
    const dateFormat = draft.processTemplate("[[dateFormat]]");
    const todaysDateString = draft.processTemplate("[[date|" + dateFormat + "]]") + " " + draft.processTemplate("[[draftTitleSuffix]]")
    const workspaceName = draft.processTemplate("[[workspaceName]]")
    const pinOnSuccess = draft.processTemplate("[[pinOnSuccess]]")
    const templateContent = draft.processTemplate("[[templateContent]]")
    
    let dailyDraft = Draft.queryByTitle(todaysDateString)
    
    if (dailyDraft.length == 0) {
        //create daily draft
        let d = new Draft()
        d.content = "# " + todaysDateString + "\n\n" + templateContent;
        d.update()
        editor.load(d);
        if (device.systemName == 'iOS') {
            app.hideActionList();
        }
        applyWorkspace()
        pinDraft()
    
    } else if (dailyDraft.length == 1) {
        editor.load(dailyDraft[0]);
        if (device.systemName == 'iOS') {
            app.hideActionList();
        }
        applyWorkspace()
        pinDraft()
    } else {
        alert("ERROR\nseveral drafts found with title \"todaysDateString\"\nclean up the mess")
        context.fail();
    }
    
    
    function applyWorkspace() {
        if (workspaceName.length != 0) {
            let workspace = Workspace.find(workspaceName);
            if (workspace) {
                app.applyWorkspace(workspace)
            } else {
                const warning = "configured workspace \"" + workspaceName + "\" not found";
                app.displayWarningMessage(warning);
                context.cancel()
            }
    
        }
    }
    
    function pinDraft() {
        if (pinOnSuccess == "true") {
            editor.pinningEnabled = true;
            editor.activate()
        }
    }

Options

  • After Success Nothing
    Notification Error
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.