I’m in no way an expert or even a novice when it comes to apple script.
I know how to copy scripts and paste them and let them run hahaha
So searching for a way to export my notes from Notes app inside Catalina, I stumbled across this option:
So far so good, but I wanted to customize it and here’s what I would like to change:
The original script asks me for a location to save the HTML files. I would like to set a default location and also have the script create a new folder inside that default location and rename it using a timestamp.
For example let’s say I have a folder on my Desktop called “Notes Backups”. So I wan’t the script to create a new folder inside “Notes Backups” and then rename that new folder using the time of when the script ran, for example it would be called “Mon-Dec20-10:54:11” (or something like that, whatever the format of the timestamp is). In the end I would end up with this:
- Notes Backups
Hope it makes sense and hope someone can give me a hand
Here’s the code anyway:
set exportFolder to (choose folder) as string -- Simple text replacing on replaceText(find, replace, subject) set prevTIDs to text item delimiters of AppleScript set text item delimiters of AppleScript to find set subject to text items of subject set text item delimiters of AppleScript to replace set subject to "" & subject set text item delimiters of AppleScript to prevTIDs return subject end replaceText -- Get an HTML file to save the note in. We have to escape -- the colons or AppleScript gets upset. on noteNameToFilePath(noteName) global exportFolder set strLength to the length of noteName if strLength > 250 then set noteName to text 1 thru 250 of noteName end if set fileName to (exportFolder & replaceText(":", "_", noteName) & ".html") return fileName end noteNameToFilePath tell application "Notes" repeat with theNote in notes of default account set noteLocked to password protected of theNote as boolean set modDate to modification date of theNote as date set creDate to creation date of theNote as date set noteID to id of theNote as string set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to "/" set theArray to every text item of noteID set AppleScript's text item delimiters to oldDelimiters if length of theArray > 4 then -- the last part of the string should contain the ID -- e.g. x-coredata://39376962-AA58-4676-9F0E-6376C665FDB6/ICNote/p599 set noteID to item 5 of theArray else set noteID to "" end if if not noteLocked then set fileName to ("[" & noteID & "] " & (name of theNote as string)) as string set filepath to noteNameToFilePath(fileName) of me set noteFile to open for access filepath with write permission set theText to body of theNote as string write theText to noteFile as Unicode text close access noteFile tell application "Finder" set modification date of file (filepath) to modDate end tell end if end repeat end tell
Really appreciate any help you guys can give me!
Model: MacBook Pro 13" Mid 2012
Browser: Safari 605.1.15
Operating System: macOS 10.15