Created
July 27, 2023 20:06
-
-
Save w4tson/e46dae74c84ce8359c61f2efc2d3e5e6 to your computer and use it in GitHub Desktop.
Apple script to export all notes in html/rtf format. Requires you make a folder called "notes" on your desktop. They will be dumped in there prefixed with an Id in the order they appear in the application
This file contains 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
tell application "Notes" | |
set i to 1 | |
repeat with theNote in notes | |
set noteName to name of theNote | |
set noteName to my replace(" ", "_", noteName) | |
set noteName to my replace("&", "and", noteName) | |
set noteName to my replace("(", "[", noteName) | |
set noteName to my replace(")", "]", noteName) | |
set theDir to (path to desktop as text) | |
set theFile to ((path to desktop as text) & "notes:" & i & "_" & noteName & ".html") | |
my write_to_file(body of theNote, theFile, false) | |
do shell script "textutil -convert rtf " & (POSIX path of theFile) | |
set i to i + 1 | |
end repeat | |
end tell | |
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean) | |
try | |
set the target_file to the target_file as text | |
set the open_target_file to ¬ | |
open for access file target_file with write permission | |
if append_data is false then ¬ | |
set eof of the open_target_file to 0 | |
write this_data to the open_target_file starting at eof | |
close access the open_target_file | |
return true | |
on error | |
try | |
close access file target_file | |
end try | |
return false | |
end try | |
end write_to_file | |
on replace(substrings, replacement, theText) | |
set astid to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to substrings | |
set textItems to theText's text items | |
set AppleScript's text item delimiters to replacement | |
set theText to textItems as text | |
set AppleScript's text item delimiters to astid | |
return theText | |
end replace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment