The script below lists all my Evernote notebooks and sends the results to the clipboard.
How could I end up with:
a sorted list of notebooks ? I can’t give you the exact number of notebooks (in case you want to use some kind of counter) because it varies.
a text file in my ~/Downloads folder called Evernote Notebook list date+time ( ie date+time stamp).txt containing the sorted list.
thanks in advance for your time and help !
tell application "Evernote"
set NotebookList to (name of every notebook)
set AppleScript's text item delimiters to return
set the clipboard to NotebookList as text
end tell
Although I generally find it easier to write in AppleScript than JavaScript for Automation (JXA), this is a situation where I think JavaScript is simpler, mainly because it has a built-in sort. The most tedious part of this script is creating the name for output file, because JavaScript (like AppleScript) doesn’t have a decent general-purpose date formatting function.
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
// Change this to where you want the file saved
var folder = '/Users/username/Desktop/'
// Get the notebook names and sort them
var myNotebooks = Application("Evernote").notebooks.name()
myNotebooks.sort()
var outString = myNotebooks.join("\n")
// Make a file name in YYYY-MM-DD-hh-mm-ss format from the current date and time
var today = new Date()
var dateParts = [ today.getFullYear(), today.getMonth(), today.getDay(), today.getHours(), today.getMinutes(), today.getSeconds() ]
dateParts = dateParts.map( n => n.toString() )
dateParts = dateParts.map( s => s.padStart(2, '0') )
var filePath = folder + dateParts.join('-') + '.txt'
// Write the notebook names to the file
var outFile = currentApp.openForAccess(filePath, {writePermission: true})
currentApp.write(outString, {to: outFile})
I just wanted to add 'Evernote Notebook List ’ to the time and date stamp, but JavaScript looks so cryptic that I don’t know where and how to insert the string.
thank you so much for all the work !!! It is a great help !!
Just insert that text into the expression for filePath.
Also, I just realized JavaScript months are zero-based, not one-based, so I had to change one other part. Here’s the full script with both changes:
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
// Change this to where you want the file saved
var folder = '/Users/username/Desktop/'
// Get the notebook names and sort them
var myNotebooks = Application("Evernote").notebooks.name()
myNotebooks.sort()
var outString = myNotebooks.join("\n")
// Make a file name from the date and time
var today = new Date()
var dateParts = [ today.getFullYear(), today.getMonth() + 1, today.getDay(), today.getHours(), today.getMinutes(), today.getSeconds() ]
dateParts = dateParts.map( n => n.toString() )
dateParts = dateParts.map( s => s.padStart(2, '0') )
var filePath = folder + 'Evernote Notebook List ' + dateParts.join('-') + '.txt'
// Write the notebook names to the file
var outFile = currentApp.openForAccess(filePath, {writePermission: true})
currentApp.write(outString, {to: outFile})
Sorry to bother you again.
I just realized that the large caps are sorted first, then the small caps.
I would like the sorting to ignore caps
thank you