Jan Hoek
Jan Hoek

Reputation: 712

How do I export notes from Evernote using AppleScript?

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! :)

Upvotes: 7

Views: 3537

Answers (5)

大白兔
大白兔

Reputation: 1

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

Upvotes: 0

Jan Hoek
Jan Hoek

Reputation: 712

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.

Upvotes: 8

anjoschu
anjoschu

Reputation: 1

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}.

Upvotes: 0

Justin Lancy
Justin Lancy

Reputation: 11

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!

Upvotes: 1

adayzdone
adayzdone

Reputation: 11238

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

Upvotes: 0

Related Questions