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:
@@ -78,6 +78,14 @@ describe('convertAppleNote', () => {
|
||||
assert.equal(convertAppleNote(note, { subject: 'LF07' }).subject, 'LF07');
|
||||
});
|
||||
|
||||
it('gives no subject to a note the export could not place', () => {
|
||||
// What `--folder Schule` produces for a note sitting loose in Schule:
|
||||
// the path relative to the folder asked for, which is nothing. A subject
|
||||
// of "Schule" would file every such note under a subject that is not one.
|
||||
assert.equal(convertAppleNote({ ...note, folder: '' }).subject, undefined);
|
||||
assert.equal(convertAppleNote({ ...note, folder: ' ' }).subject, undefined);
|
||||
});
|
||||
|
||||
it('does not repeat the title as the first line of the body', () => {
|
||||
const converted = convertAppleNote(note);
|
||||
assert.equal(converted.title, 'Erörterung');
|
||||
|
||||
Reference in New Issue
Block a user