iPhoneのメモ帳が10,000件を超えました。すっごい便利。しかしこれが消えたら大変なので、テキストに出力してバックアップを取る事にしました。
ChatGPTに聞いて、ローカルに合わせて少々改造
MacのAppleScriptでつくりました
これでひと安心です
memo2txt.scpt
tell application "Notes"
-- ★ ここにエクスポートしたいフォルダ名を入れる
set targetFolderName to "My Folder" -- ← 変更してね!
-- 指定したフォルダを探す
set targetFolder to missing value
repeat with aFolder in folders
if name of aFolder is targetFolderName then
set targetFolder to aFolder
exit repeat
end if
end repeat
if targetFolder is missing value then
display dialog "フォルダが見つかりません: " & targetFolderName buttons {"OK"} default button "OK"
return
end if
-- メモを取得
set noteList to notes of targetFolder
set saveFolder to (path to desktop folder) as text
repeat with aNote in noteList
set noteTitle to name of aNote
set noteContent to body of aNote
-- HTMLタグを削除
set cleanContent to my removeHTMLTags(noteContent)
-- ファイル名に使えない文字を置換
set cleanTitle to my replaceChars(noteTitle, {":", "/", "\\", "*", "?", "\"", "<", ">", "|"}, "_")
set filePath to saveFolder & cleanTitle & ".txt"
-- テキストファイルに保存
my writeToFile(filePath, cleanContent)
end repeat
end tell
-- HTMLタグを削除する関数
on removeHTMLTags(inputText)
set AppleScript's text item delimiters to {"<br>", "</div>", "<div>", "<p>", "</p>", "<b>", "</b>", "<i>", "</i>", "<u>", "</u>", "<span>", "</span>", " "}
set textItems to text items of inputText
set AppleScript's text item delimiters to ""
set cleanText to textItems as text
set AppleScript's text item delimiters to ""
return cleanText
end removeHTMLTags
-- 文字列の置換関数(ファイル名に使えない文字を「_」に変換)
on replaceChars(textToFix, charList, replacement)
repeat with aChar in charList
set AppleScript's text item delimiters to aChar
set textToFix to text items of textToFix
set AppleScript's text item delimiters to replacement
set textToFix to textToFix as text
end repeat
set AppleScript's text item delimiters to ""
return textToFix
end replaceChars
-- テキストをファイルに書き込む関数
on writeToFile(filePath, content)
set fileRef to open for access file filePath with write permission
set eof fileRef to 0
write content to fileRef
close access fileRef
end writeToFile