Coder Social home page Coder Social logo

set-accessed-time's Introduction

Obsidian Set Accessed Time - MacOS

Use at your own risk

I'm not really supporting this, but thought it could be useful for others.

When using Obsidian on MacOS, the "date last opened" is not updated when a file is opened. There are no settings. This is useful for tracking notes that haven't been opened in a while and may need to be archived.

This plugin simply touches the file on open, setting the access time on the file. While the atime on the time is set, you will not see "Date Last Opened" updated in the finder. You can run ls -ltu on the folder and see that it is updated.

With this plugin in place, you can use DataView to show all of the files that haven't been opened in n days.

The example below shows all files last opened more than 7 days ago and excludes the _templates and _archive folders:

Files Opened > 7 days ago
```dataviewjs
const TIME_CRITERIA = '+7';
const ASCENDING = true;
const BASE_PATH = dv.app.vault.adapter.basePath;
const ChildProcess = require("child_process");
const PRUNE = ' ! -path "{P}" '
const EXCLUDES = ['_templates', '_archive'];
let excluded = EXCLUDES.map((x) => PRUNE.replace('{P}', `${BASE_PATH}/${x}/*`)).join('');
const COMMAND = `find ${BASE_PATH} -type f -name "*.md" -atime +7 ${excluded} -exec sh -c 'file="{}"; atime=$(stat -f "%a" "$file"); formatted_date=$(date -jf "%s" "$atime" "+%Y-%m-%d %H:%M:%S" 2>/dev/null); [ -n "$formatted_date" ] && echo "[[$file]] $formatted_date"' \\; | sort -k 2 ${ASCENDING ? '-r' : ''}`;
ChildProcess.exec(COMMAND, BASE_PATH, (err, stdout, stderr) => {
	let lines = stdout.toString().split('\n');
	let result = lines.map((line) => {
		if(!line.length) return;
		return `${line.replace(`${BASE_PATH}/`, '')}`;
	})
	result = result.join('\n');
	dv.span(result);
});

The code could be cleaned up but it works.

CAVEAT - The DataView doesn't pick up these changes and auto refresh. You can just keybind the DataView force refresh, though, if it bothers you.

If there is anything wrong with the command, blame ChatGPT. ;)

To use it, create a set-accessed-time folder in your .obsidian/plugins folder. Drop the main.js and manifest.json files from the root of the repo into it. Restart Obsidian and enable in the Community Plugins section.

Support the development of the plugin

Buy Me a Coffee at ko-fi.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.