Skip to content

Instantly share code, notes, and snippets.

@kyoh86
Last active August 15, 2021 14:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kyoh86/7204276a1793bd0a69e79614c1462b05 to your computer and use it in GitHub Desktop.
Save kyoh86/7204276a1793bd0a69e79614c1462b05 to your computer and use it in GitHub Desktop.
Export notes from Note.app to PDF files.
-- 対象のフォルダの一番上を選択している状態から始める
set targetFolder to "aaa"
tell application "Notes"
activate
repeat with theFolder in every folder
if name of theFolder = targetFolder then
repeat with theNote in every note of theFolder
tell application "System Events"
key code 126
end tell
end repeat
repeat with theNote in every note of theFolder
tell application "System Events"
tell menu bar 1 of process "Notes"
click menu bar item "ファイル"
click menu item "PDFとして書き出す…" of menu "ファイル" of menu bar item "ファイル"
end tell
click button "保存" of sheet 1 of window "メモ" of process "Notes"
delay 1
key code 125
end tell
end repeat
end if
end repeat
end tell
(function(){
var destPath = "";
const targetFolder = "aaa";
const targetNote = "";
var sys = Application.currentApplication();
sys.includeStandardAdditions = true;
destPath =
sys.pathTo("documents folder", {from: "user domain", as: "alias"}).toString()
+ "/notes";
var app = new Application("Notes");
app.includeStandardAdditions = true;
for (var f=0; f<app.folders.length; f++) {
var folder = app.folders[f];
if ("" === targetFolder || folder.name() === targetFolder) {
for (var n=0; n<folder.notes.length; n++) {
var note = folder.notes[n];
if ("" === targetNote || note.name() === targetNote) {
for (var a=0; a<note.attachments.length; a++) {
var attach = note.attachments[a];
var path = destPath + "/" + attach.name();
console.log(path);
attach.save({in:Path(path), as:"native format"});
}
}
}
}
}
return null;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment