Skip to content

Instantly share code, notes, and snippets.

@Apurer
Created July 30, 2025 13:36
Show Gist options
  • Save Apurer/f9dfaca7f86114e2f6b501c3a51a998e to your computer and use it in GitHub Desktop.
Save Apurer/f9dfaca7f86114e2f6b501c3a51a998e to your computer and use it in GitHub Desktop.
tell application "Notes"
set notesFolder to choose folder with prompt "Choose where to save your exported notes:"
set allNotes to every note
repeat with aNote in allNotes
set noteTitle to name of aNote
set noteText to plain text of aNote
-- Clean file name
set cleanTitle to my cleanFileName(noteTitle)
set fileName to cleanTitle & ".txt"
set filePath to (notesFolder as text) & fileName
my writeToFile(noteText, filePath)
end repeat
end tell
-- Replace illegal file name characters
on cleanFileName(fName)
set invalidChars to {":", "/", "\\", "*", "?", "\"", "<", ">", "|"}
repeat with c in invalidChars
set AppleScript's text item delimiters to c
set fName to text items of fName
set AppleScript's text item delimiters to "_"
set fName to fName as text
end repeat
return fName
end cleanFileName
-- Write text to file
on writeToFile(content, filePath)
set fileRef to open for access file filePath with write permission
set eof of fileRef to 0
write content to fileRef
close access fileRef
end writeToFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment