Notes.app export (to PDF); append "creation date"

I’ve found an Applescript that exports notes in Notes.app to html files: https://github.com/pmatiello/notes-export/blob/master/notesExport.applescript.

What I really want is, instead of appending numbers to the start of the filenames, is to append the note “creation date” to the start of the filename in the format YYYY-MM-DD HHMMSS.

I’ve replaced the counter with a noteDate variable but then the script breaks. My questions:

  1. How can I export notes from the Notes.app and append the create date to the start?
  2. Is there a way to export, instead of HTML, to PDF?

Here’s the script with my edits:

on buildTitle(originalText)
	set normalizedText to my replace(originalText, ":", "-")
	set finalTitle to my firstChars(normalizedText, 100)
	return finalTitle
end buildTitle

on replace(originalText, fromText, toText)
	set AppleScript's text item delimiters to the fromText
	set the item_list to every text item of originalText
	set AppleScript's text item delimiters to the toText
	set originalText to the item_list as string
	set AppleScript's text item delimiters to ""
	return originalText
end replace

on firstChars(originalText, maxChars)
	if length of originalText is less than maxChars then
		return originalText
	else
		set limitedText to text 1 thru maxChars of originalText
		return limitedText
	end if
end firstChars

on writeToFile(filename, filecontents)
	set the output to open for access file filename with write permission
	set eof of the output to 0
	write ((ASCII character 239) & (ASCII character 187) & (ASCII character 191)) to output
	write filecontents to the output starting at eof as «class utf8»
	close access the output
end writeToFile


tell application "Notes"
	activate
	display dialog "This is the export utility for Notes.app.
" & "Exactly " & (count of notes) & " notes are stored in the application. " & "Each one of them will be exported as a simple HTML file stored in a folder of your choice." with title "Notes Export" buttons {"Cancel", "Proceed"} cancel button "Cancel" default button "Proceed"
	set exportFolder to choose folder
	set counter to 0

repeat with each in every note
	set noteName to name of each
	set noteBody to body of each
	set noteDate to creation date of each -- replaced counter with noteDate
	set noteTitle to my buildTitle(noteName)
	set filename to ((exportFolder as string) & noteDate & " " & noteTitle & ".html") -- replaced counter with noteDate
	my writeToFile(filename, noteBody as text)
end repeat

	display alert "Notes Export" message "All notes were exported successfully." as informational
end tell

(1) an easy way is to print the note in a pdf

(2) you wrote that the number/ creation date is at the beginning of the file name but in your code, you insert it at the end of the name, just before the name extension. I can’t guess what is the correct behavior.

(3) when I want to dateTime stamp a file I convert the date with this kind of code :

set uneDate to (current date) - 10 * days
set stamp to my horodateur(uneDate)

#=====

on horodateur(une_date)
	tell une_date to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateur

#=====

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 13 septembre 2015 17:58:45

Thanks for your comments, but we’re not in-sync with our ideas. The script I posted throws a very specific error. Can you help me identify the cause of that error?

Thanks,

John

I just tried to answer to two of your questions :

1. How can I export notes from the Notes.app and append the create date to the start?
2. Is there a way to export, instead of HTML, to PDF?

I have no use for Notes so I never opened it and have more interesting things to do that learning how it works.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 14 septembre 2015 16:21:07

I apologize for not making my questions clear enough. Your answers aren’t what I am looking for. Thank you.

Anyone else that can help?

Any question specific to an error message was actually unasked in your original post, but the error is relative to your use of the date format; because seconds include colon separators, there is never a writeable file created by open for access. Yvan’s supplied code neatly put the date into a serviceable format, although it lacks dashes, which may or may not be important.

Hi Marc - Thanks for the explanation. I didn’t understand what Yvan was trying to tell me but I’m starting to.

@Yvan - thanks for your help, despite me not recognizing it.

Will keep poking at the script and see what I can make happen.

Your script fails because you build a pathname embedding a date-time value which contain colons.

I bet that this edited version will behave correctly.

on buildTitle(originalText)
	set normalizedText to my replace(originalText, ":", "-")
	set finalTitle to my firstChars(normalizedText, 100)
	return finalTitle
end buildTitle

on replace(originalText, fromText, toText)
	set AppleScript's text item delimiters to the fromText
	set the item_list to every text item of originalText
	set AppleScript's text item delimiters to the toText
	set originalText to the item_list as string
	set AppleScript's text item delimiters to ""
	return originalText
end replace

on firstChars(originalText, maxChars)
	if length of originalText is less than maxChars then
		return originalText
	else
		set limitedText to text 1 thru maxChars of originalText
		return limitedText
	end if
end firstChars

on writeToFile(filename, filecontents)
	set the output to open for access file filename with write permission
	set eof of the output to 0
	write ((ASCII character 239) & (ASCII character 187) & (ASCII character 191)) to output
	write filecontents to the output starting at eof as «class utf8»
	close access the output
end writeToFile


tell application "Notes"
	activate
	display dialog "This is the export utility for Notes.app.
" & "Exactly " & (count of notes) & " notes are stored in the application. " & "Each one of them will be exported as a simple HTML file stored in a folder of your choice." with title "Notes Export" buttons {"Cancel", "Proceed"} cancel button "Cancel" default button "Proceed"
	set exportFolder to choose folder
	set counter to 0
	
	repeat with each in every note
		set noteName to name of each
		set noteBody to body of each
		set noteDate to my horodateur(creation date of each) -- replaced counter with noteDate # EDITED
		-- set noteDate to my horodateurAlt(creation date of each) -- replaced counter with noteDate # EDITED
		set noteTitle to my buildTitle(noteName)
		
		set filename to ((exportFolder as string) & noteDate & " " & noteTitle & ".html") -- replaced counter with noteDate
		my writeToFile(filename, noteBody as text)
	end repeat
	
	display alert "Notes Export" message "All notes were exported successfully." as informational
end tell

on horodateur(une_date) # builds yyyymmdd_hhmmss
	tell une_date to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateur

on horodateurAlt(une_date) # builds yyyy-mm-dd_hhmmss
	tell une_date to return ((text -4 thru -1 of ((its year) + 10000 as text)) & "-" & (text -2 thru -1 of ((its month) + 100 as text)) & "-" & (text -2 thru -1 of ((its day) + 100 as text))) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateurAlt

As you will see, using my handler was the required change !

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 14 septembre 2015 17:58:15

Thanks a lot for your “missing” feedback.
Trying to help in such conditions was a pleasure :rolleyes:

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mardi 15 septembre 2015 11:01:15

That did the trick as far as dates go, yes. “horodateurAlt” was just what Iw as looking for.

Thanks again.

Hello

Here is a new version which export the notes in PDFs files.

I apologize but at this time I have no way to do that without GUIScripting.

(*
Export notes from Notes to PDF files

Yvan KOENIG (VALLAURIS, France) 
2015/09/16
*)

#=====

on buildTitle(originalText)
	set normalizedText to my replace(originalText, ":", "-")
	return my firstChars(normalizedText, 100)
end buildTitle

#=====

on replace(originalText, fromText, toText)
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to the fromText
	set the item_list to every text item of originalText
	set AppleScript's text item delimiters to the toText
	set originalText to the item_list as string
	set AppleScript's text item delimiters to oTIDs
	return originalText
end replace

on firstChars(originalText, maxChars)
	if length of originalText < maxChars then
		return originalText
	else
		return text 1 thru maxChars of originalText
	end if
end firstChars

(*
on horodateur(une_date) # builds yyyymmdd_hhmmss
	tell une_date to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateur
*)
on horodateurAlt(une_date) # builds yyyy-mm-dd_hhmmss
	tell une_date to return ((text -4 thru -1 of ((its year) + 10000 as text)) & "-" & (text -2 thru -1 of ((its month) + 100 as text)) & "-" & (text -2 thru -1 of ((its day) + 100 as text))) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateurAlt


on exportAsPDF(FolderPath, pdfName)
	
	set posixFolderPath to POSIX path of FolderPath
	set pdfPath to POSIX path of (FolderPath & pdfName)
	
	tell application "System Events"
		if exists disk item pdfPath then
			delete disk item pdfPath
			delay 0.2
		end if
	end tell
	# Code borrowed to Nigel Garvey (http://macscripter.net/viewtopic.php?id=41654)
	tell application "System Events"
		tell process "Notes"
			set frontmost to true
			set {mt, mi} to {3, 8}
			
			tell menu bar 1
				log (get name of menu bar items) (*Apple, Notes, Fichier, Édition, Format, Présentation, Fenêtre, Aide*)
				--log (get name of menu bar item mt) (*Fichier*)
				tell menu bar item mt to tell menu 1
					log (get name of menu items) (*Nouvelle note, Nouveau dossier, missing value, Fermer, Tout fermer, missing value, Partager, Exporter au format PDF., missing value, Imprimer.*)
					log (get name of menu item mi) (*Exporter au format PDF.*)
					click menu item mi
				end tell # menu bar item mt
			end tell # menu bar 1
			
			repeat until exists sheet 1 of window 1
				delay 0.02
			end repeat
			tell sheet 1 of window 1
				-- log (get position of text fields) (*910, 118, 910, 148*)
				set value of text field 1 to pdfName
			end tell
			
			keystroke "g" using {command down, shift down}
			repeat until exists sheet 1 of sheet 1 of window 1
				delay 0.02
			end repeat
			tell sheet 1 of sheet 1 of window 1
				set value of text field 1 to posixFolderPath
				-- log (get name of buttons) (*Aller, Annuler*)
				click button 1
			end tell
			tell sheet 1 of window 1
				-- log (get name of buttons) (*Enregistrer, Nouveau dossier, Annuler*)
				click button 1
			end tell
			
		end tell # process
		
	end tell # "System Events"
	
end exportAsPDF

#=====

tell application "Notes"
	activate
	set nbNotes to count of notes
end tell
tell application "SystemUIServer"
	display dialog "This is the export utility for Notes.app.
" & "Exactly " & nbNotes & " notes are stored in the application. " & "Each one of them will be exported as a simple PDF file stored in a folder of your choice." with title "Notes Export" buttons {"Cancel", "Proceed"} cancel button 1 default button 2
	set exportFolder to choose folder
end tell

tell application "System Events" to tell process "Notes"
	set frontmost to true
	tell window 1
		-- log (get class of UI elements) (*splitter group, button, button, button, static text*)
		tell first splitter group
			-- log (get class of UI elements) (*scroll area, splitter, group, splitter, group*)
			-- log (get position of groups) (*717, 135, 959, 135*)
			tell first group
				-- log (get class of UI elements) (*text field, scroll area*)
				-- log (get value of first text field) (**)
				tell first scroll area
					-- log (get class of UI elements) (*table, scroll bar*)
					tell first table
						-- log (get class of UI elements) (*row, row, row, row, row, row, row, row, row, row, row, column*)
						repeat with i from 1 to count row
							tell application "Notes" to tell note i # Grab parameters to build the PDF name
								set noteName to name
								set noteDate to my horodateurAlt(creation date)
							end tell
							set value of attribute "AXSelected" of row i to true # select the note to export
							set noteTitle to my buildTitle(noteName)
							set theName to noteDate & " " & noteTitle & ".pdf"
							
							my exportAsPDF(exportFolder as text, theName) # Export the note
							
						end repeat
					end tell # 1st table
				end tell # 1st scroll area
			end tell # 1st group
		end tell # 1st splitter group
	end tell # window 1
end tell # System Events.

As you may see, I left numerous instruction which helped me to identify the UI Elements to trigger.
I left also what they returned on my system running in French.
I just commented them so they don’t eat processor cycles.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 16 septembre 2015 21:39:21

Hello,
I am looking for a way to export one note.
I can get the id, but I don’t know how to get it to export.
My preferred format is markdown, but html would be acceptable.

Thank you.

I was asked to update the script according to changes in the operating system.
Here is a version tested under High Sierra.
I apologize but my iMac is too old to host Mojave so I can’t test under this OS.

(*
Export notes from Notes to PDF files

Yvan KOENIG (VALLAURIS, France) 
2015/09/16

Modified on 2018-10-30 to take care of changes discovered in High Sierra
…
Modified again on 2018-11-05
Modified again on 2018-11-07

*)
my Germaine()

#=====

on buildTitle(originalText)
	set normalizedText to my replace(originalText, ":", "-")
	return my firstChars(normalizedText, 100)
end buildTitle

#=====

on replace(originalText, fromText, toText)
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to the fromText
	set the item_list to every text item of originalText
	set AppleScript's text item delimiters to the toText
	set originalText to the item_list as string
	set AppleScript's text item delimiters to oTIDs
	return originalText
end replace

on firstChars(originalText, maxChars)
	if length of originalText < maxChars then
		return originalText
	else
		return text 1 thru maxChars of originalText
	end if
end firstChars

(*
on horodateur(une_date) # builds yyyymmdd_hhmmss
	tell une_date to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateur
*)
on horodateurAlt(une_date) # builds yyyy-mm-dd_hhmmss
	tell une_date to return ((text -4 thru -1 of ((its year) + 10000 as text)) & "-" & (text -2 thru -1 of ((its month) + 100 as text)) & "-" & (text -2 thru -1 of ((its day) + 100 as text))) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateurAlt


on exportAsPDF(FolderPath, pdfName)
	
	set posixFolderPath to POSIX path of FolderPath
	set pdfPath to POSIX path of (FolderPath & pdfName)
	
	tell application "System Events"
		if exists disk item pdfPath then
			delete disk item pdfPath
			delay 0.2
		end if
	end tell
	# Original code borrowed to Nigel Garvey (http://macscripter.net/viewtopic.php?id=41654)
	tell application "System Events"
		tell process "Notes"
			set frontmost to true
			set mt to 3 # Index of menu "File"
			
			tell menu bar 1
				-- get name of menu bar items --> {"Apple", "Notes", "Fichier", "Édition", "Format", "Présentation", "Fenêtre", "Aide"}
				-- get name of menu bar item mt --> "Fichier"
				tell menu bar item mt to tell menu 1
					set menuNames to get name of menu items
					# According to system in use, may be 
					(*Nouvelle note, Nouveau dossier, missing value, Fermer, Tout fermer, missing value, Partager, Exporter au format PDF…, missing value, Imprimer…*)
					(*Nouvelle note, Nouveau dossier, missing value, Fermer, Tout fermer, missing value, Partager, missing value, Importer dans Notes…, Exporter au format PDF…, missing value, Épingler la note, Verrouiller la note, missing value, Imprimer…*)
					(*New Note, New Folder, missing value, Close, Close All, missing value, Export as PDF…, Share, missing value, Import, Import from iPhone or iPad, missing value, Unpin Note, Lock Note, missing value, Print…*)
					repeat with mi from 1 to count menuNames
						if item mi of menuNames contains "PDF" then exit repeat
					end repeat
					# Here, mi is the index of the menu item "Export as PDF…"
					get name of menu item mi --> "Exporter au format PDF…"
					click menu item mi
				end tell # menu bar item mt
			end tell # menu bar 1
			
			(*
			# old code
			repeat until exists sheet 1 of window 1
				delay 0.02
			end repeat
			*)
			set cnt to 1
			repeat
				if exists sheet 1 of window 1 then exit repeat
				set cnt to cnt + 1
				if cnt = 20 then error "sheet unavailable"
			end repeat
			
			tell sheet 1 of window 1
				set wichElements to class of UI elements
				if wichElements contains combo box then
					get position of combo boxes --> {{910, 118}, {910, 148}}
					set value of combo box 1 to pdfName
				else
					--> {static text, text field, UI element, static text, text field, group, radio group, group, pop up button, text field, splitter group, button, button, button}
					get position of text fields --> {{1337, 170}, {1337, 200}, {1533, 239}}
					set value of text field 1 to pdfName
				end if
			end tell
			
			keystroke "g" using {command down, shift down}
			repeat until exists sheet 1 of sheet 1 of window 1
				delay 0.02
			end repeat
			tell sheet 1 of sheet 1 of window 1
				set wichElements to class of UI elements
				# According to system in use, may be 
				--> {static text, text field, button, button}
				--> {static text, combo box, button, button}
				if wichElements contains combo box then
					set SaveIndex to -1
					set value of combo box 1 to posixFolderPath
				else
					set SaveIndex to 1
					set value of text item 1 to posixFolderPath
				end if
				name of buttons --> {"Aller", "Annuler"}
				click button 1
			end tell
			tell sheet 1 of window 1
				set theButtons to get name of buttons
				# According to system in use, may be
				--> {"Enregistrer", "Nouveau dossier", "Annuler"}
				--> {"Nouveau dossier", "Annuler", "Enregistrer"}
				click button SaveIndex
			end tell
		end tell # process
	end tell # "System Events"
	delay 0.1 # Try to run with the value .1 and if it fails before exporting every notes, increment the delay to .2, .3 … to reach the correct value or use delay 1 as I did.
end exportAsPDF

#=====

on Germaine()
	
	tell application "Notes"
		activate
		set nbNotes to count of notes
	end tell
	
	tell application (path to frontmost application as string)
		display dialog "This is the export utility for Notes.app.
" & "Exactly " & nbNotes & " notes are stored in the application. " & "Each one of them will be exported as a simple PDF file stored in a folder of your choice." with title "Notes Export" buttons {"Cancel", "Proceed"} cancel button 1 default button 2
		set exportFolder to choose folder
	end tell
	
	# Triggers System Events for 1st time to decide if we are in the "modern" structure
	tell application "System Events" to tell process "Notes"
		set frontmost to true
		set myWindow to window 1
		tell myWindow
			class of UI elements --> {splitter group, button, button, button, toolbar}
			tell first splitter group
				set whichElements to class of UI elements
				--> {button, scroll area, splitter, splitter group} # at least since High Sierra
				--> {scroll area, splitter, group, splitter, group} with # older systems
				set newStructure to whichElements contains splitter group
			end tell # 1st splitter group
		end tell # window 1
	end tell # System Events
	
	
	if newStructure then
		# at least since High Sierra
		log "case with 2 levels of splitter group" # ADDED
		tell application "System Events" to tell process "Notes"
			set frontmost to true
			tell myWindow
				-- class of UI elements --> {splitter group, button, button, button, toolbar}
				tell first splitter group
					-- class of UI elements --> {button, scroll area, splitter, splitter group}
					tell first splitter group
						-- class of UI elements --> {button, scroll area, splitter, splitter group}
						--  position of groups --> {{717, 135}, {959, 135}}
						tell first group
							-- class of UI elements --> {scroll area}
							tell first scroll area
								-- class of UI elements --> {table, scroll bar}
								tell first table
									-- class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, column}
									set nbRows to count rows
								end tell # 1st table
							end tell # 1st scroll area
						end tell # 1st group
					end tell # 1st splitter group
				end tell # 1st splitter group
			end tell # window 1
		end tell # System Events
		# No longer in System Events
		# It seems that in some cases, speaking the application Notes may loose the target in the GUI
		repeat with i from 1 to nbRows
			tell application "Notes" to tell note i # Grab parameters to build the PDF name
				set noteName to name
				set noteDate to my horodateurAlt(creation date)
			end tell
			delay 0.2
			# Re-enter System Events hoping that we no longer will loose the target
			tell application "System Events" to tell process "Notes"
				set frontmost to true
				tell myWindow
					class of UI elements --> {splitter group, button, button, button, toolbar}
					tell first splitter group
						class of UI elements --> {button, scroll area, splitter, splitter group}
						tell first splitter group
							class of UI elements --> {group, splitter, group}
							-- (get position of groups) --> {{717, 135}, {959, 135}}
							tell first group
								class of UI elements --> {scroll area}
								tell first scroll area
									class of UI elements --> {table, scroll bar}
									tell first table
										get class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, column}
										
										set value of attribute "AXSelected" of row i to true # select the note to export
									end tell # 1st table 
								end tell # 1st scroll area
							end tell # 1st group
						end tell # 1st splitter group
					end tell # 1st splitter group
				end tell # window 1
			end tell # System Events
			set noteTitle to my buildTitle(noteName)
			set theName to noteDate & " " & noteTitle & ".pdf"
			my exportAsPDF(exportFolder as text, theName) # Export the note
			
		end repeat
		
	else
		log "case without splitter group"
		tell application "System Events" to tell process "Notes"
			set frontmost to true
			tell myWindow
				class of UI elements --> {splitter group, button, button, button, toolbar}
				tell first splitter group
					-- class of UI elements --> {scroll area, splitter, group, splitter, group}
					-- position of groups --> {{717, 135}, {959, 135}}
					tell first group
						-- class of UI elements --> {text field, scroll area}
						-- value of first text field --> ""
						tell first scroll area
							-- class of UI elements --> {table, scroll bar}
							set theTable to first table # Here we have a guaranteed reference to the table
							tell theTable
								-- class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, column}
								set nbRows to count rows
							end tell # 1st table
						end tell # 1st scroll area
					end tell # 1st group
				end tell # 1st splitter group
			end tell # myWindow
		end tell # System Events
		
		repeat with i from 1 to nbRows
			tell application "Notes" to tell note i # Grab parameters to build the PDF name
				set noteName to name
				set noteDate to my horodateurAlt(creation date)
			end tell
			delay 0.2
			tell application "System Events" to tell process "Notes"
				set frontmost to true
				tell myWindow
					class of UI elements --> {splitter group, button, button, button, toolbar}
					tell first splitter group
						-- class of UI elements --> {scroll area, splitter, group, splitter, group}
						-- position of groups --> {{717, 135}, {959, 135}}
						tell first group
							-- class of UI elements --> {text field, scroll area}
							-- value of first text field --> ""
							tell first scroll area
								-- class of UI elements --> {table, scroll bar}
								set theTable to first table # Here we have a guaranteed reference to the table
								tell theTable
									-- class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, column}
									set value of attribute "AXSelected" of row i to true # select the note to exportset nbRows to count rows
								end tell # 1st table
							end tell # 1st scroll area
						end tell # 1st group
					end tell # 1st splitter group
				end tell # myWindow
			end tell # System Events
			
			set noteTitle to my buildTitle(noteName)
			set theName to noteDate & " " & noteTitle & ".pdf"
			my exportAsPDF(exportFolder as text, theName) # Export the note
			
			
		end repeat
	end if
	
end Germaine

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 février 2019 17:24:21