Wednesday, March 20, 2019

#1 2015-09-13 07:47:14 am

johncatalano
Member
Registered: 2014-03-07
Posts: 24

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-expo … pplescript.

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:

Applescript:

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


Filed under: PDF, Export, date, creation

Offline

 

#2 2015-09-13 09:59:36 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

(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 :

Applescript:

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

Offline

 

#3 2015-09-14 07:52:47 am

johncatalano
Member
Registered: 2014-03-07
Posts: 24

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

Yvan Koenig wrote:

(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 :

Applescript:

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

#=====


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

Offline

 

#4 2015-09-14 08:22:00 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

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

Offline

 

#5 2015-09-14 08:29:18 am

johncatalano
Member
Registered: 2014-03-07
Posts: 24

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

Yvan Koenig wrote:

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?

Offline

 

#6 2015-09-14 09:16:30 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 855

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

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.

Offline

 

#7 2015-09-14 09:23:22 am

johncatalano
Member
Registered: 2014-03-07
Posts: 24

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

Marc Anthony wrote:

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.

Offline

 

#8 2015-09-14 09:58:23 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

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.

Applescript:

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

Offline

 

#9 2015-09-15 03:01:25 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

Thanks a lot for your "missing" feedback.
Trying to help in such conditions was a pleasure roll


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

Offline

 

#10 2015-09-15 07:32:20 pm

johncatalano
Member
Registered: 2014-03-07
Posts: 24

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

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

Thanks again.

Offline

 

#11 2015-09-16 01:39:41 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

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.

Applescript:

(*
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 ([url]http://macscripter.net/viewtopic.php?id=41654[/url])
   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

Last edited by Yvan Koenig (2015-09-19 11:08:05 am)

Offline

 

#12 2018-11-26 05:23:18 pm

gregkelemen
Member
Registered: 2013-09-27
Posts: 1

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

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.

Offline

 

#13 2019-02-24 10:27:03 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

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

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.

Applescript:

(*
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 ([url]http://macscripter.net/viewtopic.php?id=41654[/url])
   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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)