MetaEdit plugin

I’m working on a version that supports adding elements to list items in the frontmatter.
Until then, it’s currently not supported. QuickAdd has a feature that allows you to do this, though. You use the Insert After feature in a capture.

2 Likes

I am getting a console error that was able to trace back to this plugin. Just wanted to report it here before filing on GitHub.

Thank you!

Can anyone suggest a way to add the current title of a note as an alias, so that when I change the title, I still have a way of referring to (and autocompleting on) the title before the change? I was hoping that {{title}} would work, but I can’t see how.

Are you doing some kind of scripting or templating to make this work? Has the note been created? Is this regarding many notes, or just one or two? Or, do you want some automatic workflow for it?

Legitimate questions! Definitely this is far already existing files. I’m not looking to automate this. It would mostly be one or two at a time. But even so, it would be great to just be able to have a hot key to run this. At the same time, as long as I’m getting error if there is already an existing file, it might be simpler just to use Templater with a hot key that inserts {{title}}.

This can be done in a few lines of code:

const currentFile = app.workspace.getActiveFile()
if (!currentFile) {
  return new Notice("No active file");
}
await app.plugins.plugins.metaedit.api.createYamlProperty("alias", currentFile.basename, currentFile)

You can use Templater or QuickAdd to activate the code - depending on your preferences :slight_smile:

Thanks, but I’m clearly in over my head, since I don’ t understand what “activate the code” refers to. :person_shrugging:

1 Like

Is there any way to have the date automatically update to today’s when the file is moved across lanes in kanban helper?

I’d love to have it update datestarted with a date when moved to doing and datefinished when moving to completed.

2 Likes

was there a update related to editing task and kanbans? i really like such a feature but can’t find anything

Hi,

When I specify that a property is “multi” (or I’ve selected the “all multi” option) - the value gets wrapped in “[ ]”.

Even if there is only one value available for the property.

I want:

Property: Value

But when multi is involved, it gives me:

Property: [Value]

Hi.
TL:DR Before I get lost in a rabbit hole of research, would it theoretically be possible to use MetaEdit to automate appending a new value to a list of values in a specific field in a different note that you specify (not the current one)?

What I really want to try and achieve is to use fields with list values (multi in MetaEdit parlance) across several notes so that they get populkated in the following way:

Say you have two fields of “offspring” and “parents”

I want to be in one note and tell it to append a note link to the “offspring” field of the current note and at the same time append the current note as a link to the “parent” field in the note being linked to from the current note.

It sounds like there should be a way (albeit complicated, and presumably using Buttons) and if there is then I’m willing to try and put the time in to get it to work… but I’m not big on coding and before I start banging my head against a code wall I thought I’d ask here.

One thing I’m not sure of is whether the MetaEdit API allows appending a specific value to a current field which may or may not already have a list of values.

Curious. Does this make a difference? As far as I could work out this simply means that Obsidian recognises that the field can have a list of values. If there is only one, presumably that still works just the same as not having the brackets there (in terms of dataview searches, etc)?

I also thought the point of using multi was specifically so that it DID do this?

Hi, it is. I have done it mixing QuickAdd macros and metaEdit API.

This is for instance, the macro I use to create a new task which is a subtask of the current file. It will append the new task name to an array in the master task, and in the subtask also a reference to the master.

I know I have a hell with promises/async/await, but bear with me, I’m not a js dev.

module.exports = async (params) => {
  const {
    app,
    quickAddApi: { yesNoPrompt, inputPrompt, executeChoice },
  } = params;
  const { update, getPropertyValue } = app.plugins.plugins['metaedit'].api;

  const master = app.workspace.getActiveFile();
  var deps = await getPropertyValue('depends-on', master);
  if (!deps) {
    deps = [];
  }
  if ((await getPropertyValue('type', master)) != 'task') {
    await yesNoPrompt('Current file is not task type');
    return;
  }

  const name = await inputPrompt('Subtask Name');
  deps.push(name);

  const masterOps = [
    update('depends-on', `[${deps.toString()}]`, master),
    executeChoice('log-task-event', {
      'Log Event': `Created subtask: [[${name}]]`,
    }),
  ];

  await Promise.all(masterOps);
  Promise.all([executeChoice('create-new-task', { Name: name })]).then(
    async () => {
      const dep = app.vault.getAbstractFileByPath(`tasks/backlog/${name}.md`);
      await executeChoice('log-task-event-to-inactive-file', {
        'File Path': dep.path,
        'Log Event': `Subtask of [[${master.basename}]]`,
      });
      await update('master-task', master.basename, dep);
    }
  );
};

The reason I await all the masterOps is because my create-new-task macro changes the scope to the new file and I was having a bug related to it. Anyway, I’m paid for coding other stuff and not my OCD macros, so I found that was an easy workaround.

OT: any change proposal to this hell of asyncs is well received :slight_smile:

Hello,
I would like to know if I can use this plugin (or another one) to edit a field (name and value) in different md files at the same time. An example of this case is to rename the field ‘note_type’ to ‘type’ in all the md files of the selected folder.

2 Likes

I realy dont get what the Feature: “Progress Properties that automatically update properties/fields” does.
has anyone an example for me? I tried out the settings but dont understand what this feature does.

How would you adapt this code to only show metadata from the current note?
I tried, but it’s just showing an empty space and this error in the console:

TypeError: Cannot read properties of null (reading ‘querySelector’)
at eval (eval at (plugin:dataview:1:1), :35:24)
at DataviewInlineApi.eval (inline-api.ts:424:16)
at evalInContext (inline-api.ts:425:7)
at asyncEvalInContext (inline-api.ts:435:32)
at DataviewJSRenderer.render (js-view.ts:26:19)
at DataviewJSRenderer.onload (refreshable-view.ts:22:14)
at DataviewJSRenderer.e.load (app.js:1:863626)
at t.e.addChild (app.js:1:864027)
at t.addChild (app.js:1:1408443)
at Object.addChild (app.js:1:1407468)


const app = this.app;
const metaedit = app.plugins.plugins["metaedit"];

const init_dom = (row) => {
	const sel = `table.dataview.table-view-table td > span > a[data-href='${row.file.path}']`;
	const tr = dv.container.querySelector(sel).closest("tr");
	
	const labels = tr.querySelectorAll("._dataview-labels");
	for (let i = 0; i < labels.length; i++) {
		const data = labels[i].data
		const file = app.vault.getAbstractFileByPath(row.file.path);
		const prop = {key: data.name, content:data.actual, type: data.type};
		labels[i].addEventListener('click', async (evt) => {
			metaedit.controller.editMetaElement(prop, [], file);
		});
	}
}

const field = (row, name, type) => {	
	let data = {};
	data.row = row;
	data.name = name;
	data.actual = row[name];
	data.value = row[name];
	data.type = type || 1;

	const el = this.container.createEl('span', {"text": row[name] || "-"});
	el.classList.add("_dataview-labels");
	el.data = data;
	return el;
};

try {
	var workspace = dv.container.closest("div.workspace-leaf");
	var title = workspace.querySelector("div.view-header-title");
	var prefix = title.innerHTML;
	
	dv.table(
		["Name", "Status", "Area", "Date Ceated"], 
		[dv.current().file.link, 
		dv.current().Status, 
		dv.current().Area, 
		field(dv.current(), 'Date_created')]
    );
	
	setTimeout(function(){
		for (let i = 0; i < pages.length; i++) {
			init_dom(pages[i]);
		}
	}, 0);
} catch (err) {
	window.console.info(err);
}

Hi @Christian.
I have trouble replicating one of your examples in Github for MetaEdit.
Here is my issue Discord
I would really appreciate any help.
Thanks for your plugins are amazing and really help our workflow.
Thanks again.

1 Like

Trying to add the title of a linked note to Properties. I add field Related, then add the [[Note Title]] as the value; when I go to the files, the plugin has added quotes around my title: [[“Note Title”]], which isn’t actually a link to the file I want.

Is there a workaround? Is this a feature not a flaw? What am I missing?