Send to Evernote on Mac OS X

Being able to add files into Evernote is a particularly useful feature.  On my Windows PC I have an option when I right click on a file to send it to Evernote.  By default my Evernote installation on my Mac doesn’t provide this option, so I decided to address this shortcoming with a service.

Automator allows you to create new services and these can form the basis for context sensitive options.  I set about writing an AppleScript that would take selected files and import them into Evernote.  The script below is what I came up with.

on run {input}
    tell application "Evernote"
        repeat with SelectedFile in input
                create note from file SelectedFile notebook "Auto Import"
            on error errMessage number errNumber
                if the errNumber is equal to 4 then
                    -- The file being imported is not supported
                    set userCanceled to false
                        display dialog "Your Evernote account does not support the import of this type of file.  Why not consider upgrading?" buttons {"Cancel", "Go Premium"} default button "Cancel" cancel button "Cancel" with icon caution
                    on error number -128
                        set userCanceled to true
                    end try
                    -- If the user wishes they can be taken to the Evernote premium upgrade page
                    if userCanceled is false then
                        tell application "Safari"
                            open location ""
                        end tell
                    end if
                    -- Unspecified failure
                    display alert "Import into Evernote failed" message "Error(" & errNumber & "): " & errMessage as warning
                end if
            end try
        end repeat
    end tell
end run

The script includes some error handling.  One specific error I’ve pulled out is for error number 4 - which is flagged up by Evernote when a file being imported is not permissible by the account type (i.e. you’re a freemium user with trying to import an unsupported file type).  Originally I targeted looking at file sizes in Finder before passing them to Evernote as freemium and premium have two different file size limits.  However when Evernote receives a request to create a note from a large file that is not supported by the freemium account it gives an option for the user to upgrade.  Oddly Evernote didn’t seem to do this for unsupported files so I decided to include this in the script.  Non-specific errors are also relayed to the user through a dialog displaying the standard error message and number.

To make this a service, follow these steps:

  1. Open Automator and create a new service.
  2. Add the “Run AppleScript” action.
  3. Copy the script above into the new action.
  4. Set the service to receive selected “files  or folders” (option located just above the action).
  5. Save the service with a suitable name.

Open Finder then locate one or more files to import into Evernote.  Right click to display the context menu and select the name of your service.  This should then begin the process of creating a note for each file in Evernote.

Author: Stephen Millard
Tags: | applescript | evernote |

Buy me a coffeeBuy me a coffee

Related posts that you may also like to read