Bear: Batch Editing Notes
Batch editing Bear notes on macOS requires essentially two steps:
- Executing SQLite queries on Bear’s database, which is located at
~/Library/Group Containers/9K33E3U3T4.net.shinyfrog.bear/Application Data/database.sqlite
[1]. - Force syncing local changes to iCloud.
¶Executing SQLite queries
Here is a list of tooling options for SQLite queries:
sqlite3
(Python Standard Library)- DB4S (DB Browser for SQLite) (open-source GUI)
- SQLPro for SQLite (proprietary GUI)
Once the database is properly loaded, look for column ZTEXT
in table ZSFNOTE
, where the content of notes is stored. Execute the queries below as needed.
Find notes with duplicate content
1 | SELECT ZTITLE, ZTEXT, count(*) COUNT FROM ZSFNOTE GROUP BY ZTEXT HAVING COUNT > 1; |
Find %TEXT%
1 | SELECT ZTEXT, instr(ZTEXT,'%TEXT%') |
Replace %ORIG%
with %REPL%
1 | UPDATE ZSFNOTE SET ZTEXT = REPLACE(ZTEXT, '%ORIG%', '%REPL%'); |
Advanced find and replace
- The documentation of SQLite core functions is available here.[2]
- Wildcards can be used, following the
LIKE
operator, where%
and_
are the equivalent of*
and.
in regular expression.
1 | /* Here, `substr(ZTEXT, 1, 6)` returns the first 6 characters |
¶Force syncing to iCloud
This is where things get a bit hacky. As Bear only syncs when changes are detected in ZTEXT
, operations such as pinning / unpinning, trashing / restoring, archiving / unarchiving do not effect syncing, as they only update columns ZPINNEDDATE
, ZTRASHEDDATE
or ZARCHIVEDDATE
.
Instead, use tagging / untagging, since tags are store in ZTEXT
, and their changes are treated as updates to ZTEXT
.
Here are the steps:
- In Bear, create a temporary tag, e.g.
#__stage__#
. - Select the notes to be synced, drag them onto
#__stage__#
which should now be at the top of the left panel. - Wait for syncing to complete, then delete
#__stage__#
.
[Drag and Drop]
Bear. Where are Bear’s notes located. ↩︎
For practical examples, refer to w3resource’s SQLite Core Functions. ↩︎