# How to access properties of a file with Obsidians API?

**URL:** <https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203>\
**Category:** Devs: Plugins & API\
**Created:** [November 13, 2023, 10:30am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203 "2023-11-13T10:30:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Zeratul](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/p/f19dbf/32.png) [@Phillip\_Zeratul](https://forum.obsidian.md/u/Phillip_Zeratul)\
**Post date:** [November 13, 2023, 10:30am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/1 "2023-11-13T10:30:10Z")

</div>

Hi, I’m developing a plugin for Obsidian trying to manipulate proterties in files. So how should I get and set a property in code?

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [November 13, 2023, 10:42am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/2 "2023-11-13T10:42:04Z")

</div>

Not sure if there are better ways for a plugin, but I’ve found that the `app.FileManager.processfrontmatter()` is useful for manipulating properties. Do a search for this and you’ll find multiple examples on usage.

Be aware, that depending on your use case of your plugin you _might_ get into race conditions if multiple plugins wants to write stuff to the same file. If this occurs, you could in some cases use a `setTimeout()` to delay your writing to the file.

Also note that, as of now, when Obsidian (and its API) changes properties, it’ll also reformat the frontmatter due to the usage of the js-yaml library, and this is to be expected.

---

<div class="post-metadata">

**Author:** ![Acylation](https://forum.obsidian.md/user_avatar/forum.obsidian.md/acylation/32/42777_2.png) [@Acylation](https://forum.obsidian.md/u/Acylation)\
**Post date:** [November 13, 2023, 10:57am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/3 "2023-11-13T10:57:15Z")

</div>

Maybe these are included in metadataCache

---

<div class="post-metadata">

**Author:** ![Phillip\_Zeratul](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/p/f19dbf/32.png) [@Phillip\_Zeratul](https://forum.obsidian.md/u/Phillip_Zeratul)\
**Post date:** [November 14, 2023, 1:22am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/4 "2023-11-14T01:22:09Z")

</div>

Thanks.  
I stumbled upon this.app.metadataCache.getFileCache() once and I was looking for something like cachedMetadata.properties, but combining with @holroy’s answer, I realized that the properties can be found in cachedMetadata.frontmatter.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [November 14, 2023, 2:59pm UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/5 "2023-11-14T14:59:36Z")

</div>

I’ ve not worked that much with the actual metadataCache, but I’d be a little weary on _changing_ properties in the cache. It’s one thing to read out of the cache somehow, but I would most likely not try to change the cache unless using some proven and known methods. I’m also not sure whether the metadataCache always hold all values, or if there is some lazy-load mechanism in play (based on recently opened files or similar).

So be a little careful when venturing into the world of the cache (especially of other plugins and/or main Obsidian stuff), as you’re partially in unchartered territory. 😃

---

<div class="post-metadata">

**Author:** ![Acylation](https://forum.obsidian.md/user_avatar/forum.obsidian.md/acylation/32/42777_2.png) [@Acylation](https://forum.obsidian.md/u/Acylation)\
**Post date:** [November 15, 2023, 2:29am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/6 "2023-11-15T02:29:47Z")

</div>

Yeah I agree that for modifications the method `processFrontMatter` would be more recommended.

---

<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:** [November 22, 2023, 2:30am UTC](https://forum.obsidian.md/t/how-to-access-properties-of-a-file-with-obsidians-api/71203/7 "2023-11-22T02:30:07Z")

</div>

Closed on November 22, 2023, 2:30am UTC

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