Skip to content

Instantly share code, notes, and snippets.

@appendjeff
Created August 27, 2025 01:27
Show Gist options
  • Select an option

  • Save appendjeff/8e55308b315520cffe98c9bda57c682b to your computer and use it in GitHub Desktop.

Select an option

Save appendjeff/8e55308b315520cffe98c9bda57c682b to your computer and use it in GitHub Desktop.
Mark As Read Obsidian Plugin
// main.js - Save this in a new folder in your .obsidian/plugins directory
// Also, save a manifest file next to the plugin
const { Plugin } = require('obsidian');
class MarkAsReadPlugin extends Plugin {
async onload() {
console.log('Loading Mark as Read plugin');
// Add command to mark note as read
this.addCommand({
id: 'mark-note-as-read',
name: 'Mark note as read',
callback: () => {
this.markNoteAsRead();
}
});
}
async markNoteAsRead() {
const activeFile = this.app.workspace.getActiveFile();
if (!activeFile) {
console.log('No active file');
return;
}
try {
// Use Obsidian's built-in API to process frontmatter
await this.app.fileManager.processFrontMatter(activeFile, (frontmatter) => {
frontmatter.isRead = true;
});
console.log('Added isRead: true to frontmatter');
// Close the current active file
const activeLeaf = this.app.workspace.getActiveViewOfType(require('obsidian').MarkdownView);
if (activeLeaf) {
activeLeaf.leaf.detach();
console.log('Closed active file');
}
} catch (error) {
console.error('Error updating frontmatter or closing file:', error);
}
}
onunload() {
console.log('Unloading Mark as Read plugin');
}
}
module.exports = MarkAsReadPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment