Created
December 19, 2017 15:57
-
-
Save rel/48f8d68c21a6b47a02e911f910ed3303 to your computer and use it in GitHub Desktop.
A simple AppleScript (written in javascript) to collect notes from Apple Notes into a single html document for easy printing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// options | |
var startDate = new Date(2017, 10, 1); // the start date for notes collection. Remember, in js January = 0. | |
var fileName = "notes.htm"; // the name of the file to create | |
// use the notes app | |
var notes = Application("notes"); | |
var collected = []; | |
// collect notes modified after the start date | |
for(var i in notes.notes) { | |
var note = notes.notes[i]; | |
var date = note.modificationDate(); | |
var startingDate = startDate; | |
collected.push({ | |
id: note.id(), | |
name: note.name(), | |
created: note.creationDate(), | |
modified: date, | |
body: note.body() | |
}); | |
if(startingDate > date) break; | |
} | |
// sort notes by their `last modified` date | |
collected.sort(sorter); | |
// format the results as html | |
var html = '<style>body { font-family: arial } h1 { font-size: 16px; margin-bottom: 10px; } timestamp { font-size: 12px; color: #bcbcbc; }</style>'; | |
for(var i in collected) { | |
var item = collected[i]; | |
console.log(i, item.modified, item.name); | |
html += "<h1>" + item.name + "</h1>\n" + | |
"<timestamp>" + item.modified + "</timestamp>\n" + | |
"<p>" + item.body + "</p>\n" + | |
"----------------\n\n"; | |
} | |
// write to file | |
var t = Application('TextEdit'); | |
var nDoc = t.Document().make(); | |
nDoc.name = fileName; | |
t.documents[fileName].text = html; | |
// all done :) | |
console.log("Done"); | |
////////////// | |
function sorter(a, b) { | |
var res = 0; | |
if(a.modified > b.modified) res = 1; | |
if(a.modified < b.modified) res = -1; | |
return res; | |
} | |
////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Debdut Save this file locally then run it in the Script Editor on your Mac (https://support.apple.com/en-au/guide/script-editor/scpedt1069/mac)