How do I export notes from Evernote using AppleScript?
Asked Answered
A

5

7

I'm trying to export notes from Evernote v.3.3.0 in HTML format to a location on disk using AppleScript. The task at hand doesn't seem to be particularly complicated, but my being relatively new to Evernote, and completely new to AppleScript doesn't help much... ;)

Here's what I have come up with so far - any comments are much appreciated!

tell application "Evernote"
    set allmynotes to find notes
    set outputpath to "/Users/{myusername}/Desktop/Test"
    export allmynotes to outputpath format HTML
end tell

From what I understand, exporting as HTML creates a single file per note, which is why I assumed I needed to specify an output folder name instead of an output file name. Another assumption is the fact that the script, when double-clicked, will run with the credentials of the active user; on my machine, this user has sufficient permissions to write to the specified folder.

Results until now are Evernote got an error: Unable to remove existing output file." number 1 and Evernote got an error: Unable to create output directory.. Any ideas?

Many thanks in advance! :)

Aylesbury answered 13/8, 2012 at 18:14 Comment(0)
A
8

Victory at last! The problem had nothing to do with my script, and everything with the fact that I had installed Evernote from the App Store. The App Store version, unlike the version that can be downloaded from evernote.com, is limited by App Sandboxing in Mac OS X. Now, with the non-App Store version installed, the scripts above work perfectly.

Thanks again for answering, and for those experiencing the same issues - I hope that your problems are also solved by the above.

Aylesbury answered 7/8, 2013 at 18:10 Comment(0)
G
1

Think it's a bug in 3.3 -- I have written a fair number of AppleScripts for Evernote (including ones with working export functions) and have recently encountered the same types of "permission" errors.

When I reached out to Evernote Developer Support, they replied that their team is currently looking at the issue. I will forward this page to them for their reference and, hopefully, version 3.3.1 will bring a fix!

Gayl answered 16/8, 2012 at 13:55 Comment(4)
Nice to hear from you! Of course I'm aware of your site - that's where I found the first inspiration to use AppleScript for my little backup procedure! :) In his response above, adiayzdone claims that things work OK on his Snow Leopard machine. Maybe the problem has something to do with Mountain Lion? Have a great weekend! :)Aylesbury
Seems that we will need to be more patient - according to the Mac App Store, version 3.3.1 only increases scanner support - no fixes for the AppleScript interface - which is confirmed by the fact that my script still doesn't work as expected...Aylesbury
Hmmm... Was hoping that version 5.0 would solve this issue, but (unless I'm doing something seriously wrong) it doesn't. :(Aylesbury
I'm having the same issue. Used to work perfectly fine but hasn't in a few versions now. The accepted answer was what I was already doing and doesn't work for me.Slating
R
0

You were close:

set outputpath to (path to desktop as text) & "Evernote Test"
do shell script "mkdir -p " & quoted form of POSIX path of outputpath

tell application "Evernote"
    set allmynotes to find notes
    export allmynotes to outputpath format HTML
end tell
Rossuck answered 13/8, 2012 at 22:41 Comment(3)
Thanks! :) I'm thinking that I may have misunderstood my problem. Running your script when the test folder doesn't exist gives me Evernote got an error: Unable to create output directory.. If I manually create the folder first, it complains about Evernote got an error: Unable to remove existing output file.. I'm afraid the error messages don't exactly bring me closer to a solution? What does Evernote want from me, in order for this to work?Aylesbury
Thanks again for the effort you're putting into this - much appreciated! Does the script work on your machine? On mine, it keeps giving me Evernote got an error: Unable to remove existing output file.. I'm starting to believe the syntax for the export verb in AppleScript's dictionary might be incorrect or incomplete for the HTML format? After all - exporting as ENEX (single file) or HTML (one file per note) should probably require different input, right?Aylesbury
That's strange. So, on your machine, the Evernote Test folder on your desktop contains an HTML file for each note, each optionally accompanied by a resources folder containing the note's attachments? In that case, I think I'll accept your answer, thank you once again, and focus my attention on the question how my setup might be different. :)Aylesbury
F
0

On Evernote 5.2.1 (Mac OS X 10.8.4), I can verify adayzdone's answer to work reliably, regardless of whether the output folder already exists. If the given folder does exist, Evernote will move it to the trash and create a new one.

From the original question, I gather uncertainty on how to deal with edge cases (such as an earlier export folder already existing). Here's code for handling such a case with a dialog.

set folderName to "Latest Evernote HTML Export"
set exportFolder to (path to documents folder as text) & folderName as text
tell application "Finder"
    if exportFolder exists then
        set answer to the button returned of (display dialog "This will overwrite the previous Evernote HTML export" buttons {"Stop", "Overwrite"} default button 1)
        if answer is equal to "Stop" then
            error number -128 -- end script with error "User Cancelled"
        end if
    end if
end tell

tell application "Evernote"
    set allNotes to find notes
    export allNotes to exportFolder format HTML
end tell

Hint for testing: To avoid exporting the complete Evernote library (which can be very large), one can replace the two occurrences of allNotes with {firstNote, secondNote}.

Fresnel answered 5/8, 2013 at 19:52 Comment(0)
E
0
set folderName to "Latest Evernote HTML Export"
set exportFolder to (path to documents folder as text) & folderName as text
tell application "Finder"
    if exportFolder exists then
        set answer to the button returned of (display dialog "This will overwrite the previous Evernote HTML export" buttons {"Stop", "Overwrite"} default button 1)
        if answer is equal to "Stop" then
            error number -128 -- end script with error "User Cancelled"
        end if
    end if
end tell

tell application "Evernote"
    set allNotes to find notes
    export allNotes to exportFolder format HTML
end tell
Eldwon answered 15/8, 2017 at 12:52 Comment(1)
Welcome to Stack Overflow! While this might be a valuable hint to solve the problem, a good answer also demonstrates the solution. Please edit to provide example code to show what you mean. Alternatively, consider writing this as a comment instead.Afterword

© 2022 - 2024 — McMap. All rights reserved.