Drafts to particular place in Obsidian daily note

Has anyone created a file-based action for sending from Drafts to a particular place in today’s Obsidian Mobile daily note? (rather than simply append or prepend to it)

I’ve found the Obsidian QuickAdd plugin macro to insert content, say, after “## Log” in daily note within Obsidian. But I’d love to do from Drafts without having to launch Obsidian Mobile app. (As file-based action ‘Save in Obsidian’ does nicely for new notes.) Thanks.

I also thought about that - the only „problem“ with that is that users might have different formats for the daily note filename so it’s something that a user would need to configure before using the action.

I‘ll look into it :blush:

1 Like

There you go @mwjames I created too actions to add content to the Daily Note, one just to append / prepend it and one to add it to a specific section:

Add to Obsidian Daily Note
Add to Obsidian Daily Note Section

Please go through the docs and let me know if it works for you :slight_smile:

1 Like

Wow, thanks, FG! :tada: Will report after checking out.

1 Like

FG, thank you so much! This solves my problem.

I did need to add this to the ‘Add to Obsidian Daily Note Section’ script at line 30:

// MWJ 20221026: Added missing textAddPrefix
//splits[1] = “\n” + draft.content + “\n” + splits[1]
splits[1] = “\n” + textAddPrefix + draft.content + “\n” + splits[1]

For some reason, in my Obsidian setup in macOS, the “\n” adds too many line breaks, so I removed them. In contrast, they’re needed in my Obsidian setup in iOS.

That’s weird…
Are you sure that it adds more newlines and it’s not a display thing on macOS?
Maybe also a plug-in that affects it on macOS?
I can’t test it right now on a Mac since I don’t have access to my own for some time.

The action only adds the newlines to the file so it should work similar on macOS and iOS…

Sure you did not just have extra line feeds in the text of the draft you were testing with on the Mac? It looks like the action just passes along the full content of the draft, it would not strip out extra feeds in the draft.

Actually also a good idea to strip them… I’ll see if more people run into that „issue“

Could easily be the heavy plugin/CSS customization I have in my macOS instance of vault that’s not present in my sync’d Obsidian Mobile instance. Sending from iOS Drafts to sync’d Obsidian vault for use in macOS is my main use case, and that’s landing perfectly (in my case, as bulleted list item, no space before or after, under “### Log”).

I’m excited about this, and am expecting to use it a lot. Thank you!

1 Like

@FlohGro when I run this action the text gets added at the very end of the obsidian note rather than after ## Log. Any ideas?

Which action did you run and how did you configure it?

Sorry for the lack of detail.

I am using the “Add to Obsidian Daily Note Section” action and have configured to to append after

Log

I think I just figured it out. If I select prepend it will insert at the right spot. Looks like append was going to the end of the note.

It shouldnt append it to the end of the note - if I should look into it I’d need the exact configuration and also your template for the daily note :blush: if it works for you now that’s fine, too

Awesome Work! Thanks a lot. Worked rightaway!

Two questions i’d like to ask:

  1. Are the “Alerts” of second section and relevant text for development purposes only? (I commented them out :smile:)
  2. When doing an append, the script adds a new line right after the section, is it necessary? Below is a context:

I’m doing an “append” on “## Jounral” section in daily notes.

My note is like this:

## Tasks
*top three tasks*

## Journal
*Time-based journal along the day*
- something maybe already here
- another thing

## Dataview summary
...etc

When I trigger the action, the journal section becomes:

## Journal
[   ]                          <-- New Empty line gets added here
*Time-based journal along the day*
- something already here
- another thing
- **New text from Drafts Action**

## Dataview summary
...etc

It’s not a big issue, but got me interested to ask about it.

Thanks again for the actions!

  1. I thought there are only alerts when an error happened in the action. Could you let me know which ones you’re talking about?

  2. the beeline is added since this is (as far as I know) correct markdown style to have newlines around a heading. It should be possible to remove that from the script if you’re annoyed by it.
    Finding the sections and adding text to it wasn’t too easy and caused some issues for different section headings.

Thanks for the reply,

Ah got it, didn’t expect the beeline (just learned the name!) in an append. I’ll test things out the coming days. It might be caused due to my .md structure.

Made quick screen recording showing the flow and alerts (link)

For the alerts, those two:

let textToInsert = ""
let linesToInsert = [gFirstSection,gSecondSection]
// distinguish newline amount if there is currently no text between the two sections:
alert(gSecondSection) // <-- first alert
let firstSectionInsert = ""
let secondSectionInsert = ""
// check text add mode and add text accordingly:
if (textAddMode == "append") {
      alert(relevantText)  // <-- second alert

Thanks for the recording, you can definitely comment them out.

I’ll check my local version of the action and push an update.

1 Like

Thanks for your efforts!

Also i fixed the new line thing for me if anyone mildly annoyed by it.

Just changing this:

firstSectionInsert = gFirstSection + "\n\n"

to this:

firstSectionInsert = gFirstSection + "\n" // removed extra \n

I feel it’s there to handle a certain edge case for some markdown structures use-cases, but couldn’t know what. Any how this solved it for my structure.

This action + apple drafts shortcuts (run background action with text) is life savior!

1 Like

Great you figured this out - so I can remove it from my todo list :joy: glad this action helps you so much!