Export Apple Notes to stdout, and one folder at a time
`console.log` in JXA writes to standard error, not standard output, so `> notes.ndjson` produced an empty file while every note scrolled past on the terminal. Both streams now go through NSFileHandle, which is the only way to be sure which one you are on; the comment says so, because the next person will reach for console.log too. `--folder` was a substring match applied after each note's body had already been read. It now matches a whole path segment — `Schule` takes Schule and everything under it and leaves Musikschule alone — and is checked before the body, which is the one expensive property and is what makes a large library take minutes. The path is recorded relative to the folder asked for, because the import reads its last segment as the subject: `Schule/Deutsch` has to arrive as `Deutsch`, and a note loose in `Schule` has to arrive with no subject at all rather than one called "Schule". Not run: this needs a Mac with Notes, and there is none here. The JXA stream behaviour is the documented one and the folder logic is plain string work, but the script itself is still unexercised.
This commit is contained in:
@@ -156,11 +156,17 @@ If you have notes in Apple Notes, migrate them now — see
|
||||
[NOTES.md](NOTES.md#migrating-out-of-apple-notes). Briefly, on the Mac:
|
||||
|
||||
```bash
|
||||
osascript -l JavaScript scripts/export-apple-notes.js > notes.ndjson
|
||||
# --folder takes that folder and everything under it; leave it off for all notes
|
||||
osascript -l JavaScript scripts/export-apple-notes.js --folder Schule > notes.ndjson
|
||||
wc -l notes.ndjson # one line per note
|
||||
schulcloud note import notes.ndjson --dry-run # look first
|
||||
schulcloud note import notes.ndjson
|
||||
```
|
||||
|
||||
The export runs on the Mac; the import does not have to. The CLI talks to the
|
||||
server over HTTP, so copying the `.ndjson` to whatever machine already has the
|
||||
CLI configured is the shorter path.
|
||||
|
||||
Import **once**. Re-running creates second copies, because the importer cannot
|
||||
tell an edited note from a new one with the same title.
|
||||
|
||||
|
||||
@@ -189,11 +189,22 @@ not the clumsy route to your notes — it is the only one.
|
||||
|
||||
```bash
|
||||
osascript -l JavaScript scripts/export-apple-notes.js > notes.ndjson
|
||||
osascript -l JavaScript scripts/export-apple-notes.js --folder Schule > schule.ndjson
|
||||
```
|
||||
|
||||
The first run raises a macOS permission dialog ("Terminal wants access to
|
||||
Notes"); without it every note comes back empty. `--folder Deutsch` exports one
|
||||
Notes folder.
|
||||
Notes"); without it every note comes back empty.
|
||||
|
||||
**`--folder Schule` exports one folder and everything under it.** Folder names
|
||||
are matched whole, not as a fragment, and the path is recorded relative to the
|
||||
one you named — so `Schule/Deutsch` arrives as the subject `Deutsch`, and a note
|
||||
sitting loose in `Schule` arrives with no subject rather than one called
|
||||
"Schule". Reading a note's body is the expensive part, so filtering here rather
|
||||
than afterwards is also what makes a large library finish.
|
||||
|
||||
The records go to standard output and the progress line to standard error, so
|
||||
`> notes.ndjson` gets exactly the notes. Check it took: `wc -l notes.ndjson`
|
||||
should be the number the script reported.
|
||||
|
||||
Then look at what it would do, and do it:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user