Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save archangel-irk/57f1e33906211d5459d6ebfd327e4ee9 to your computer and use it in GitHub Desktop.
Save archangel-irk/57f1e33906211d5459d6ebfd327e4ee9 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