QuickAdd macro building - Refactoring a note and then adding front matter

What I’m trying to do: I’m trying to create a macro that, on hotkey command, will refactor a selection in an existing note and then prompts me for a capture that allows me to add strings to the front matter for dataview use.

What I’ve done: (see attached images) I have built the macro using 1) “Note Refactor: Extract selection to new note”, obsidian command, followed by 2) “insert note metadata”, a capture that I built.

What is happening: The macro executes. The note refactors to a new note, the font matter input pop-ups are triggered. The problem is that the front matter is then dropped into the original note at the refactor point and not the new refactored notes. I realize that this is due to the original note still being the active note. Capture does allow me to capture a specified file, and you can even define that file as a variable, but I can’t figure out how to poll the new refactored notes file name.

The QuickAdd macro:

My insert front matter QuickAdd capture:


If naming the file to capture to:

1 Like

Neat! What are your settings for the “Note Refactor” - does it leave behind a link to the new note?

Yes; so if you know how I could poll that string, there might be a way to add it into the “File name format” for the QuickAdd capture. Although, I think I’d have to leave a message in Github for the QuickAdd dev about the needed format. (I am not a coder. I’m just brute forcing my way through this by trial and error).

1 Like

I am consistently surprised by how much of “being a coder” is trial and error!
I think there is an “command” or “editor command” in the macro options for “follow link on current line” or “follow link under cursor”. So you could maybe use that to go to the new file and then capture into it?
I have code somewhere that does something like this, but less automatically, and then goes “back” to the file where I was. The going back part might be useful: I’ll edit this post to add it when I am back at the right machine. EDIT: I misremembered slightly, in that I create a backlink rather than going back, but inside a jsquickadd block in my capture format the expression this.app.workspace.lastOpenFiles[0] refers to the file open before the current one. Maybe that will be useful!

Hello Guvna_McBacon,

I was trying to do the same thing and this post helped me a lot. Thanks!

In addition, I was able to add the capture to the refracted file. You probably have figured that out but if you have not, adding the editor command, “Select active line” will solve the problem.