MetaEdit plugin

How doable/easy would that be for someone like me to do (i.e. someone with no experience of creating/writing scripts)?
Any pointers by any chance?
I think it’d be good value for others too because I’ve seen it asked many times in the discord server by people like me.
Thanks again Christian!

Sorry realised I didn’t use ‘reply’ in my comment so you might not have seen it.

Sorry if this is answered elsewhere, I searched far and wide.
Is there any way to batch edit a selection of notes, links or dataview records? I seem to remember doing this, but I suppose I might have done it with search and replace in an external editor.
(Later) Ahh that’s it, I probably selected a folder and used the contextual menu “add Yaml property to all files in this folder (and subfolders)”.
Nevertheless, does anyone have a better solution?

2 Likes

I will attempt to answer you both, @kenanmike & @jwb, since your questions are somewhat similar.

MetaEdit currently provides one way to do mass editing, which is the context menu which adds a YAML property to files in a folder. This was my first go at adding support, and I have been working on something much grander since. However, that takes a lot of time, because there are many other things that I also need to do to achieve it.

Instead, a fine solution - which works for me - is to use the API and do some scripting.
I use QuickAdd to run my scripts through macros.

I mostly do so on a case-by-case basis, but try to abstract over the specific needs if it makes sense to do so. This also allows me to share scripts which might serve as inspiration:

For mass editing, the general idea is to get all the files you wish to target (through the Obsidian API), and then using the MetaEdit API update function on them.

I hope this helps :slight_smile:

1 Like

Thanks a lot for this! Haven’t done any programming in 20 years, but managed to modify the dataviewjs example to do an autoprop when clicking the button.

My challenge though, is this: The API seems only to allow for updating existing properties, and not add new ones… I’d love for my button to create the property if it does not already exist, instead of… doing nothing :man_shrugging:

Any pointers appreciated if it is actually possible… Thanks :slight_smile:

Hey! So, there’s actually an undocumented API function called createYamlProperty. The way I usually approach it is to first check if a given property exists, and then either create or update it using the API:

// MetaEdit API Interface functions
autoprop: (propertyName: string) => void;
update: (propertyName: string, propertyValue: string, file: TFile | string) => Promise<void>;
getPropertyValue: (propertyName: string, file: (TFile | string)) => Promise<any>;
getFilesWithProperty: (propertyName: string) => TFile[];
createYamlProperty: (propertyName: string, propertyValue: string, file: TFile | string) => Promise<void>;
getPropertiesInFile: (file: TFile | string) => Promise<Property[]>;
1 Like

Thanks for your demo and your plugin! Can I update two properties with the same click? I mean in your “click and update” example~

And one more question, can I add two buttons in the same line?

Fantastic! Thanks for helping :slight_smile:

1 Like

I answered Andy’s questions elsewhere, but here are the answers in case anyone is wondering:

  1. Yes, just call the update function for the different properties in the same function using JavaScript.

  2. By calling createButton multiple times, you can create multiple buttons on the same line - if done at the same time in the loop.

1 Like

many thanks for your reply!

1 Like

@Christian I tried to follow the examples listed on GitHub but I am not able to run the API example “New Task Template”. I have created a template with the provided code and when I call tamplater to insert the template I am not getting any MetaEdit options. It just inserts the template directly. Can you tell me where I went wrong?

P.S It would be really helpful if you could create a video for MetaEdit just like the quick add video

Hi Christian,
Does the Kanban helper function work in the Kanban beta? I’m trying to use it with RC2.0 and I’m wondering if i’m just wasting my time.

(later)
After using it with the official release, I can confirm that the helper no longer works, and resets column names in a kanban destructively.
Thanks

I’m trying to use Templater and MetaEdit to get the property value in the current file (in this example “Pronunciation”) and add it to a new line in the file. Here’s the code I’m using.

<%*
const {getPropertyValue} = this.app.plugins.plugins["metaedit"].api;
tR = `Pronunciation:: ${await getPropertyValue("Pronunciation", "TFile")}`
 %>

It’s returning as “undefined”, but the value of the field in the file is not “undefined”. Am I using the wrong syntax? Is there something else I should be doing?

Hey! That’s pretty odd. Are you getting any errors or something?

A MetaEdit video could be very cool! I have a lot of things I’d like to add & improve before then, though :slight_smile:

Hi @jwb, thank you for testing this! I’ll fix it when I can - for now, you should just disable it.

Hey @millerstevew!

Is the file called “TFile”? Because it’s looking for that property in a file called “TFile”.

Here’s the documentation for the function.
I realize that I should probably have written what exactly a TFile is.

A TFile is a type of object you can get using the Obsidian API. However, that isn’t super intuitive to non-programmers, so I allow users to instead use the file path.
So where you have "TFile", you should put the file to the path (relative to your vault).

Hey thanks for the reply, I figured it out. Is there any way to add a date picker to the auto property?

Awesome! Glad to hear that.

Currently, no. I’ll add it to my backlog, though :slight_smile:

Thanks, @Christian. Is it possible for TFile to refer to the current file?

My hope is to use Templater to update the metadata I add to a file (both YAML and dataview). Here’s an example.

Pretend I have a file:

---
tags: people
alias: 
template: people
version: 2
---

# Metadata

Pronunciation:: 
Context:: [[Wyoming St]]

---

Then, pretend I update the template for these kinds of files to include a new field (e.g., Address::):

---
tags: people
alias: 
template: people
version: 2
---

# Metadata

Pronunciation:: 
Context:: 
Address::

---

I want a template that I can “expand” that will populate with the current file’s metadata already filled in. I am able to access the values for the YAML front matter using Templater. Mind you, I’m not a programmer, so I have no idea if there’s a better way to do this, but the following works for updating the YAML front matter:

---
<%* if ((tp.frontmatter.tags) == null) { _%>
tags: people
<%* } else if (tp.frontmatter.tags.contains("people")) { _%>
tags: <% tp.frontmatter.tags %>
<%* } else { _%>
tags: people, <% tp.frontmatter.tags %>
<%* } _%>

<%* if ((tp.frontmatter.alias) == null) { _%>
alias: 
<%* } else { _%>
alias: <% tp.frontmatter.alias %> 
<%* } _%>

template: people
version: 2
---

I’m hoping to use MetaEdit to update the dataview values. I think that a Templater Javascript Execution Command can handle the rest of the “expansion,” using the MetaEdit API. I’m thinking that I’ll essentially add one line per dataview value, like you do in the New Task template on your GitHub page.

<%*
const {getPropertyValue} = this.app.plugins.plugins["metaedit"].api;
tR = `
Address:: ${await getPropertyValue("Address", "TFile")}
`
 %>

I just don’t know how to make “TFile” or whatever I’m supposed to put between Address:: ${await getPropertyValue("Address", and )} refer to the current file.