MetaEdit plugin

Thanks for this plugin Christian. I’m trying to understand if I could theoretically batch add tags to a load of notes in the same folder and/or with some common information. I have notes of different publications which are in the folder ‘Publications’ and which contain the dataview field ‘type:: publication’. I want to add the tag #publication/academic to all of them. Could I do this by using your plugin to grab the ‘type::’ Dataview field and updating it to:
tag:: #publication/academic
type:: publication

(I need to keep the type field.)

1 Like

You can use MetaEdit to accomplish this for sure. You’d probably need to create a small script to accomplish it :slight_smile:

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?

3 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:

2 Likes

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[]>;
3 Likes

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).

1 Like

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