Auto-Send Sentences to Other Notes?

Things I have tried

I apologize if this has been asked before

I’ve look through community plugins and the obsidian forum for solutions but didn’t find anything

What I’m trying to do

I want to automatically scan through a note and send particular sentences to other notes:

For example if this sentence was tagged with $#reference it would be sent my reference note

Ideally I would be able to set which tags would send to which notes and even send to sub heading within notes

1 Like

Neat idea!
One possible approach: I have a QuickAdd (community plugin) macro that lets me press a keyboard shortcut and move the line I’m on to a specific section in my daily note. I have very similar one tied to a different keyboard shortcut that will open up the Quick Switcher for me to select a file and then move the line I’m on to the same pre-specified section in that note instead. (I use this for sending to other day’s notes. It would definitely break if I selected a file that didn’t have the section name that the macro sends it to.) This approach works for me because I like the idea that my files will not change unless I explicitly command them to (via the keyboard shortcut). If you’d prefer to type a tag to trigger the move I have no idea how to do that part.

I hope other folks can share their approaches and that between all of them you’ll find something that sounds good!

2 Likes

You can do this with the dataview plugin and inline metadata, mostly. If you can separate the sentences that need to be sent onto their own lines, you can do it like this in your notes:

reference:: Here is a sentence that should appear in another place.
differenttopic:: This sentence should appear in a different place.
reference:: This sentence should appear in the same place as the first, and it’s a little longer, but that’s okay.

And then in your reference note, you can put this dataview code:

$=dv.list(dv.pages('"original/notes/folder"').where(p => p.reference).sort(p => p.file.name, 'desc').map(p => p.file.link + " " + p.reference));

And in the reference note, you’ll get:

  • link-to-file Here is a sentence that should appear in another place.
  • link-to-file This sentence should appear in the same place as the first, and it’s a little longer, but that’s okay.

Hope that helps!

4 Likes

Try Obsidian 42 – Text Transporter. It is not automatic, but it has many options and works well.

2 Likes

Awesome, thanks for the tip! I’ll try this out now:

Just a few questions:

Do I just copy paste the dataview code into my reference note as is? or do I need to alter it in some way? ie. change the “original/notes/folder” to the folder path of my source note?

Would this code run automatically or would I need to trigger it somehow?

Thanks for the help :sweat_smile:

1 Like

The code does just get put right into your note, but you’ll need to enclose the code in backticks, and there are two ways to do that:

One is in a block, where you start with 3 backticks and the word dataviewjs [```dataviewjs] and then the code on the next line (starting with “dv.list…” - take out the “$=”) and then three more backticks on the next line.

And the other way is inline, where you would copy my code exactly (keeping the $= in front) but you’ll need to enclose that in single backticks. So one backtick just before the $ and one backtick just after the last semicolon. (The forum renders them as code, so I can’t type them in!)

And make sure you’re using backticks, not single quote marks! (On my keyboard, the key is to the left of the 1/! key.)

And yes, you’ll need to change the path in the code to the folder where the notes that you want to pull the comments from are. So for me, I am pulling stuff out of my daily notes, which live in a folder called “Journal”. So that bit looks like [dv.pages(’“Journal”’)] for me. It will go down into subfolders - like I have mine organized into months - so you don’t need to specify every subfolder, just the top level one.

So the basic gist is that somewhere in one of my daily notes, there is text that looks like this:

coolthing:: My husband made the best lamb stew last night!

And then somewhere else (doesn’t have to be in the same folder), I have a note called Cool Things.md and all that is in that note is the code I pasted above (with ‘Journal’ in the path and ‘coolthing’ replacing ‘reference’). But when I look at that note in reading and/or live preview editing modes, I’ll see the list of coolthings that have been pulled from my daily notes. It is just there - you don’t have to do anything or run anything to see it.

Hopefully that gives you enough to go on! Enjoy!

3 Likes

Nice! How do you do get it to select the current line as the capture input. And remove the existing line?

I took a look at the text transporter plugin source, so no worries about providing an explanation.

Sounds great! How did you do that? I’m not familiar with the macro

This is great! Thank you

This is exactly what I’m looking for EXCEPT if I have ‘coolthing::’ twice in the same note, I get both inline references appearing on the same line in the reference note, but separated by a comma. So I am try to get this:

  • link-to-file Here is a sentence that should appear in another place.
  • link-to-file This sentence should appear in the same place as the first, and it’s a little longer, but that’s okay.

but I am getting this:

  • link-to-file Here is a sentence that should appear in another place.,This sentence should appear in the same place as the first, and it’s a little longer, but that’s okay.

How did you separate the results into bullet points if you have the same inline reference twice from the same note?

One option is to use flatMap() and build up an array of the separate entries, here is the version expanded into multiple lines:

`$= dv.list(dv.pages('"original/notes/folder"')
  .where(p => p.reference)
  .sort(p => p.file.name, 'desc')
  .flatMap(p => dv.func.typeof(p.reference) == "array" 
    ? p.reference.map(ref => p.file.link + " " + ref) 
    : [ p.file.link + " " + p.reference ])
  )`

Here we use a ternary operation, condition ? true-expr: false-expr, to split the two cases of a single reference in a file, and multiple references in the same file. If it’s an array, we map each of the values to our wanted output, and in the other case we make an array with the single value with want out of that file.

Concatenated into one line:

`$= dv.list(dv.pages('"original/notes/folder"').where(p => p.reference).sort(p => p.file.name, 'desc').flatMap(p => dv.func.typeof(p.reference) == "array" ? p.reference.map(ref => p.file.link + " " + ref) : [ p.file.link + " " + p.reference ])) `

Remember to change reference to your specific field, and to change the original/notes/folder to match your setup.

In my test setup the above


query returned:

1 Like