Dedicated calendar view in bear

Maybe someone will find this useful. I created a small swift helper designed to work with apps like Alfred, Keyboard Maestro etc. to quickly switch to next/previous daily note in Bear with a keyboard shortcut. This won’t create new notes if they don’t exist, but navigate to the closest existing one, mimicking Obsidian’s native Open previous/next daily note command. Currently only works with YYYY-MM-DD titles, but you can modify source if you want.

The reason I created this is because I couldn’t find a better way to get the current note’s ID from Bear without a) obliterating the clipboard by copying Note Identifier via AppleScript or b) significantly impact performance. Commands execute in ~150 ms, making it feel decently fast.

If anyone prefers the AppleScript route, here’s what I used:

Previous note:

tell application "Bear" to activate
tell application "System Events"
	tell process "Bear"
		click menu item "Copy Identifier" of menu "Note" of menu bar 1
	end tell
end tell

set noteID to the clipboard

set dbPath to (POSIX path of (path to home folder)) & "Library/Group Containers/9K33E3U3T4.net.shinyfrog.bear/Application Data/database.sqlite"

set q to "SELECT ZTITLE FROM ZSFNOTE WHERE ZTITLE < (SELECT ZTITLE FROM ZSFNOTE WHERE ZUNIQUEIDENTIFIER = '" & noteID & "') AND ZTITLE GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' AND ZTRASHED = 0 ORDER BY ZTITLE DESC LIMIT 1"

set targetDate to do shell script "sqlite3 " & quoted form of dbPath & " " & quoted form of q

if targetDate is "" then
	display notification "No previous daily note found"
	return
end if

open location "bear://x-callback-url/open-note?title=" & targetDate

Next note:

tell application "Bear" to activate
tell application "System Events"
	tell process "Bear"
		click menu item "Copy Identifier" of menu "Note" of menu bar 1
	end tell
end tell

set noteID to the clipboard

set dbPath to (POSIX path of (path to home folder)) & "Library/Group Containers/9K33E3U3T4.net.shinyfrog.bear/Application Data/database.sqlite"

set q to "SELECT ZTITLE FROM ZSFNOTE WHERE ZTITLE > (SELECT ZTITLE FROM ZSFNOTE WHERE ZUNIQUEIDENTIFIER = '" & noteID & "') AND ZTITLE GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' AND ZTRASHED = 0 ORDER BY ZTITLE ASC LIMIT 1"

set targetDate to do shell script "sqlite3 " & quoted form of dbPath & " " & quoted form of q

if targetDate is "" then
	display notification "No next daily note found"
	return
end if

open location "bear://x-callback-url/open-note?title=" & targetDate
1 Like