# How to use app.fileManager.processFrontMatter

**URL:** <https://forum.obsidian.md/t/how-to-use-app-filemanager-processfrontmatter/73467>\
**Category:** Help\
**Tags:** templater\
**Created:** [December 22, 2023, 9:40am UTC](https://forum.obsidian.md/t/how-to-use-app-filemanager-processfrontmatter/73467 "2023-12-22T09:40:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterInBrisbane](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@PeterInBrisbane](https://forum.obsidian.md/u/PeterInBrisbane)\
**Post date:** [December 22, 2023, 9:40am UTC](https://forum.obsidian.md/t/how-to-use-app-filemanager-processfrontmatter/73467/1 "2023-12-22T09:40:19Z")

</div>

Hi Team,

I am trying to use Quick add, with templater, to prompt for a couple of front matter entries, all hangin off a button.

I have buttons that work. I have templates that work. I have quick add’s that work. I have done all these things in the past. But now for the first time ever, I am trying to write to front matter. That seems to be a dark art.

Behold my templater code,

> \<%\*  
> console.log(“1”)  
> let bandName = await tp.system.prompt(“Band Name”)  
> let venue = await tp.system.prompt(“Venue”)  
> let theName = tp.file.title  
> let titleName = tp.date.now(“YYYY-MM-DD”)  
> console.log(“2”)  
> let baseFolder = “/Music/Bands/” + `${bandName}` + “/”  
> console.log("target file is ", tp.config.target\_file)  
> await tp.file.move(baseFolder + titleName)  
> console.log("now target file is ", tp.config.target\_file)  
> console.log(“3”)
> 
> await app.fileManager.processFrontMatter(tp.config.target\_file,  
> (fm) =\> {  
> console.log('this is the front matter ', fm)  
> fm[‘Location’] = “[[Locations/” + `${venue}` + “]]” })
> 
> console.log(“4”)
> 
> console.log(`${bandName}`)  
> await app.fileManager.processFrontMatter(tp.config.target\_file,  
> (fm) =\> { fm[‘band’] = `${bandName}` })
> 
> await app.fileManager.processFrontMatter(tp.config.target\_file,  
> (fm) =\> {console.log('fm is now ', fm)})
> 
> console.log(“5”)  
> %\>

The bit that console logs the front matter before I play with it, says that the items I am looking for exist. The very last console log saying “fm is now…” clearly prints out that I have set the front matter to what I want it to be.

But then it just ends, and opening the file shows no front matter saved. Is there a “save” call I am meant to make that I missed?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![gino\_m](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gino\_m](https://forum.obsidian.md/u/gino_m)\
**Post date:** [December 23, 2023, 10:03am UTC](https://forum.obsidian.md/t/how-to-use-app-filemanager-processfrontmatter/73467/2 "2023-12-23T10:03:07Z")

</div>

I also have problems using this.  
I have a Templater Js script where I replace some text formatting then based on these operations I want to add to the frontmatter.

```auto
// Check if code needs to be executed
if (codeExec) {
    app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
        frontmatter['danglinglink_sorted'] = true;
        });
// Had setTimeout method here before but had timing issues with it – frontmatter key was added, then many times disappeared soon after – but even after removing setTimeout, the issue recurs
// if (codeExec) {
    // setTimeout(() => {
        // app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
            // frontmatter['danglinglink_sorted'] = true;
        // });
    // }, 300);
}

```

Not sure if this method is superior or better in any way for current file:

```auto
const currentFile = app.workspace.getActiveFile();
// ...rest of script
await app.fileManager.processFrontMatter(currentFile, frontmatter => {
        frontmatter['danglinglink_commentedout'] = true;

```

As you can see, the formerly used setTimeout method I commented out to try out the script without it but I didn’t manage to solve the issue.

The issue being: Obsidian throws the confounding **Merging changes automatically…** pop-up, and in about 1-2 seconds, the newly added property disappears.

- I had talked about this before:  
[Automatically update last modified date in note - #19 by AlanG](https://forum.obsidian.md/t/automatically-update-last-modified-date-in-note/51776/19)

It doesn’t happen every single time so I reckon the sending of the message and the root of the issue is that Obsidian saves the file (as it does every 2 seconds) at the same time one is manipulating the frontmatter.

Current workaround: undo the Templater command (press CNTRL+Z once or twice) and try again so the property value sticks.

I am not sure the MetaEdit way of adding a property would be exempt of having the same effect. I suspect not.

EDIT:  
See my recent revelations [here](https://forum.obsidian.md/t/new-properties-and-templater-prompts-and-commands/66425/28).

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [March 22, 2024, 10:03am UTC](https://forum.obsidian.md/t/how-to-use-app-filemanager-processfrontmatter/73467/3 "2024-03-22T10:03:14Z")

</div>

Closed on March 22, 2024, 10:03am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
