Skip to content

Instantly share code, notes, and snippets.

@mm53bar
Last active September 14, 2022 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mm53bar/512dc26c540f199fe6101581de3cc410 to your computer and use it in GitHub Desktop.
Save mm53bar/512dc26c540f199fe6101581de3cc410 to your computer and use it in GitHub Desktop.
Track recent files in Obsidian's daily notes
  • Update your notes path in recent.rb
  • Save ca.aream.recent.plist to ~/Library/LaunchAgents/ca.aream.recent.plist
  • Save recent.rb to ~/bin/recent (you may have to create the bin folder and run chmod +x recent to make the script executable
  • Run launchctl load ~/Library/LaunchAgents/ca.aream.recent.plist to start the launchd service
  • Check your notes path to see if RECENT.md was created!

If that all worked, install the Templater plugin for Obsidian and create a Daily Note template that includes [[RECENT]] - I've included my template to get you started.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ca.aream.recent.plist</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/tmp/recent.err</string>
<key>StandardOutPath</key>
<string>/tmp/recent.out</string>
<key>ProgramArguments</key>
<array>
<string>/Users/mike/bin/recent</string>
</array>
</dict>
</plist>

<% tp.date.now("dddd, MMM D, YYYY") %>

[[<% tp.date.now("YYYY-MM-DD", "P-1Y") %>]] | [[<% tp.date.now("YYYY-[W]W") %>]]

Recent Notes

<% tp.file.include("[[RECENT]]") %>

Daily Notes

#!/usr/bin/env ruby
notes_path = "#{ENV['HOME']}/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/"
recent_filepath = notes_path + 'RECENT.md'
files = Dir.glob("#{notes_path}**").select {|f| File.mtime(f) > (Time.now - (7*24*60*60))}
recent_notes = files.map{|filepath| File.basename(filepath).chomp('.md') unless filepath.match(/RECENT|TODO|WEATHER|_TEMPLATES|_ATTACHMENTS/)}.compact
File.open(recent_filepath, 'w') do |file|
recent_notes.each do |filename|
file.write "- [[#{filename}]]\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment