Add metadata into a plaintext notes as something like header

Hi,

Just begin to use DEVONthink and it seems very powerful.I just wonder automation can make this happen or not.

I import my RSS feeds and read it in DEVONthink. When coming across some articles I really like I will save it as plaintext and send it to obsidian vault. Is it possible to add the URL and tags, these two metadata, at the top of this article plaintext note.

Then I think a little bit further, is there a way to add metadata to plaintext notes with a template?

Since I know nothing about code and I searched forum finding this post, seems it has no solution for now. Sorry for post one more time here, but I still want to try in case we have solutions now.

Adding URL metadata to files - Meta Woes

Thanks for your time.

Yes. I guess, you also want to know how to do that. Basically, I’d write a script along these lines:

  • convert the selected record to plain text
  • add the URL and tags list (separated by what, BTW?) to the top of this text
  • save the converted record to whatever location
  • tell Obsidian to import it

Only drawback: There’s no “convert to plain text” method. So I converted to markdown and added the URLs and tags (separated by blanks and hashes) to the frontmatter. The script is not tested at all, use at your own risk and try it out on copies of your documents first. .

(() => {
  const app = Application("DEVONthink 3");
  const targetGroup = nil; /* Define if you want the converted record in another group than the original */
  const conversionParams = {to : "markdown"};
  if (targetGroup) {
     conversionParams.in = targetGroup;
  }
  records = app.selectedRecords();
  /* Loop over all currently selected records supposing they are RSS feeds (or whatever you want them to be */
  records.forEach(r => {
    /* get the URL */
     const url = r.url();
   /* get the tags and convert them into "#tag1 #tag2 #tag3 ..."
      Change to your liking 
*/
     const tags = r.tags().map(t => `#${t} `);
     /* Convert to MD */
     const newRecord = app.convert(r, conversionParams);

     /* Set the frontmatter of the new record to contain the URL and the tags list */
     newRecord.plainText = `---\n${url}\n${tags}\n---\n${newRecord.plainText()}`;

     /* Now add newRecord to Obsidian, maybe like shown here
        https://discourse.devontechnologies.com/t/script-copy-devonthink-textbundle-markdown-folder-to-obsidian-folder/65877 
*/
  })
})()

Thanks for your kind help, it seems not working. It says something is not right.

Maybe make it simple, just add url and tags at the top the notes (only for plain text format) , I will convert to markdown and move to Obsidian vault by myself. Will this be a little easier?

I suppose the error message is bit more detailed than that. Care to quote it?

1 Like

Sure.


(() => {


firs line
Grammatical errors
Expected to be an expression, but found “>”.

Well, this is a _Java_Script script, not AppleScript. Set your language selection in the Script Editor to “JavaScript” and try again.

Lol. I changed the language then I run again. It says:


Error: ReferenceError: Can’t find variable: nil


You can change the “nil” to “undefined”.

I wrote the script to show how it could be done and I did not test it. It will not do what you want anyway without adding the code for Obsidian. So you have to get a grip on it and fix remaining errors/problems.

Ok. I try to fix.
Many thanks