How should I report the current modification date of a file living outside my vault?

Things I have tried

I’ve looked at Dataview and Shell Commands plugins, but Dataview does not work on files outside the vault, and Shell Commands requires explicit operation by the user.
I’m leaning toward using a cron job or other outside process that refreshes a date of a file outside of Obsidian, using a shell script that writes this value into a vault file. In fact I currently do something like this anyhow for maintaining certain of my vault files, so this is likely the approach I’ll be using as it will work. But it feels a bit unclean somehow. :stuck_out_tongue:
Another approach would be to move the file into my vault, but it’s not a markdown file and I don’t want to bloat my vault with binary files too much. Hmm…
Is there any other approach that could work in the vast plugin world of Obsidian?
The crux of my problem, I suspect, is that like a web server, Obsidian cannot see files outside my vault. Am I correct about that? Any workarounds other than what I’m thinking here?
Thanks!

What I’m trying to do

I’m trying to put the modification date for an external file in a markdown file in my vault.
Here is the markdown. The file is “Timelines.graffle”.

---
Aliases: [  ]
tags: 
meeting:
 type: "planning-tool"
 status: "active"
 next: "every few days"
 last: 2022-11-22
---
#  My Timeline
- [Timelines.graffle](<file:///Users/rcook/Library/Mobile Documents/iCloud~com~omnigroup~OmniGraffle/Documents/2021-2022 Timelines.graffle>)
- I'd love to put something like this pseudocode here:  "=Timelines.graffle.mtime" 
- 
- Don't forget to update last in YAML <--- THIS IS THE PROBLEM I'M TRYING TO SOLVE, MANUAL UPDATES.  
- defer deep dives, stick to time

Moving the file into the vault just for getting the last modification time, or even installing a plugin just to check that seems like a little bit of overkill.

A simple dataviewjs snippet to get this time:

```dataviewjs
const fs = require('fs').promises
const lastModified = (await fs.stat('/path/to/file')).mtime
dv.span(lastModified.toString())
```

This prints the last modification time of the file, which in my testing where way outside the vault. And I think there exists utilities to convert the javascript data into something more usable by dataview, but I don’t have those readily available just now.

Using a cron job, or other outside process will potentially create an timing issue if the file is changed somewhat often, and you’ll also be dependant on something outside of Obsidian, so I reckon I would just go ahead and check the modification time when it’s needed.

If you need to store this timestamp somewhere in the vault, you could possibly use Templater, but that would give the modification timestampt at the time you ran the template insert.

In other words, it comes down to why you want it, and for what. Templater could insert it into a given file, dataviewjs can get it whenever you want, and a cron job (or similar) could update another file every so often.

Hope this helps,
Holroy

2 Likes

That is very cool and I definitely will save that code for later. However, it seems like neither method perfectly meets my needs.
What I’m doing right now is showing a list of “meetings with myself” using dataview.
So I have a file called “Planning Meetings.md” which makes a table of my planning meetings.

## Planning Meetings
```dataview
table file.mtime as "Last Modified", meeting.next as "Next Meeting" 
where meeting.type = "planning-tool" and meeting.status = "active"
where !contains(file.name, "Template")
sort file.mtime
```

Here is how the table looks today:

My intent is that the top of the list is the next meeting I want to get done.
I don’t know how to use the timestamp in Timelines.graffle in this table.
So I created another file, “My Timelines” which is just a pointer/wrapper around “Timelines.graffle,” where the real work is done.
Here is My Timeline.md:

---
Aliases: [  ]
tags: 
meeting:
 type: "planning-tool"
 status: "active"
 next: "every few days"
 last: 2022-11-22
# generated from [[Planning and Inspiration Contexts]] on 202207071642
---
#  My Timeline
- [Timelines.graffle](<file:///Users/rcook/Library/Mobile Documents/iCloud~com~omnigroup~OmniGraffle/Documents/2021-2022 Timelines.graffle>)
- Don't forget to update last in YAML
- defer deep dives, stick to time

In order for this to work, I have to modify “My Timelines.md” artificially because it’s just a pointer to the actual timeline. It’s clunky.
Can you think of a way to create the table in “Planning Meetings.md” but using the actual Timelines.graffle file instead of this wrapper business?
Sorry if I’m being unclear

thanks again for this. I am getting an error when i try to use your code. Apologies for my lack of debugging skills but could you help me figure out my error? :slight_smile:

Haha solved my own question.

const lastModified = (await fs.stat('filepath', (err, fileobj) => 
{ if (err) { console.log(err) } else { thing=fileobj} } ))

does something useful, at least enough for me to plod onward using the fileobj in question.
lastModified does not get set here. Have to use callbacks.
Cheers and THANK YOU for the big help

1 Like

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