Evernote watched folders on OS X
Tuesday, May 11, 2010 at 11:28PM |
Permalink Following on from the send to Evernote addition for Evernote I also wanted to reproduce the Windows Evernote watched folders feature. This allows a file moved to a specific folder to be automatically imported into a new note within Evernote and again can be accomplished with AppleScript.
The script to import the file into Evernote should be attached to the folder. Right click on a folder and select "Folder Actions Set-up..." to access the naming and specifying for the folder's action.
The script is heavily based upon the send-to processing in the previous post so if you're interested in some of the details please have a read of that too.
NOTE: Thanks to Stephen Aument for finding an issue and fix in Mountain Lion. If you have an issue with the script silently failing, try changing:
create note from file item_path notebook "Auto Import"
to:
create note from file this_item notebook "Auto Import"
on adding folder items to this_folder after receiving these_items
repeat with anItem from 1 to number of items in these_items
set this_item to item anItem of these_items
set the item_info to info for this_item
set the item_path to this_item as text
tell application "Evernote"
try
create note from file item_path notebook "Auto Import"
on error error_message number error_number
if the error_number is equal to 4 then
-- The file being imported is not supported
set userCanceled to false
try
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"
activate
open location "https://www.evernote.com/Checkout.action"
end tell
end if
else
-- Unspecified failure
display alert "Import into Evernote failed" message "Error(" & error_number & "): " & error_message as warning
end if
end try
end tell
end repeat
end adding folder items to
beep 1
I use an unsynchronised notebook called "Auto Import" to take in files dropped into my particular watched folder. This means that I don't arbitrarily use up my monthly quota. You should amend this to the name of whatever notebook you would like to import to.
AppleScript,
Evernote | in
Technology 

Reader Comments (54)
Just wanted to say thanks for this. Been using it for ages and it was one the first things I installed after this weekends OS re-install. Cheers.
Thanks very much - I've been looking for a solution like this for awhile. Makes 1-click scanning to evernote a reality for me!
This is terrific, I was looking for this functionality. Many thanks for a useful Christmas present.
How would I go about choosing a specific folder for the files to go into ? And would it be easy to do an import & send to trash functionality ?
Merry Christmas and Happy New Year to you !
Doug.
Okay to auto delete the item after importing, replace...
create note from file item_path notebook "Auto Import"with
create note from file item_path notebook "Auto Import"
tell application "Finder"
delete the this_item
end tell
I'm not 100% sure I understood the first part of your question, but I think you're asking how to set up the folder for this, here's how I did it, but if that's not what you were getting at let me know and I'll see if I can help.
First of all put your AppleScript into the AppleScript editor and save the script into "{user}\library\scripts\folder actions" where {user} is whatever your personal folder is on your Mac.
Now create yourself a folder - pretty much anywhere you like. Ctrl+Click/Right Click on the folder and (assuming you're using Snow Leopard) select "Folder Actions Setup..." from the "Services" sub-menu. Now select your script from the resulting list of folder action scripts and that's it.
I then created a shortcut/alias for my folder and popped it onto my desktop for easy access.
I hope that all helps.
Merry Christmas....
Thanks for your efforts! Your other script, send file to Evernote, works great! But this script, I can't get it to work properly. I should make this script within Automator as an Mapaction, right?
Michael.
You can either create the script in the AppleScript Editor as in my previous comment or if you're using Automator select "Folder Action" as a template for the workflow and then add the "Run AppleScript" action. Paste the script into the details for this action. Save it with a suitable name. As far as I know (and I'm sure there are many Mac users out there who may be able to correct me if I'm mistaken) this should be the same as saving the script to a specific location. I think both options have worked for me in the past.
Fantastic script. Picked it up via Don McAllister's most recent tutorial. ScreenCastsOnLine Tutorial #284. I encourage anyone having problems with the script to view SCO0284. Thank you. I have many other uses for this script.
If anyone does have any problems with the script let me know and I'd be more than happy to help if I can.
I have implemented the Script (THANKS!!) I tested with my FREE account and a PDF. I got the "Your Evernote account does not support the import of this type of file. Why not consider upgrading?" and I pressed Cancel...then the PDF appeared in my Evernote. Why? I am confused as to why PDF import is not supprted on a Free acct and why when I pressed Cancel, the file still appeared in my EN. Thanks!
Michael.
The script has a check on line 13 where it looks for a return code of 4. From my experimentation when I wrote this script (I've since gone premium BTW), this was the code returned when I tried to import a file that wasn't supported by the free account.
Off the top of my head I don't know why it would successfully import the file and return that particular error number. Can you repeat this issue and is it repeatable just with the one PDF?
This is the first time I've used a custom script to automate functions on my Mac. When I tried to implement this solution using the Automator method, I didn't have much luck. I was successful via the method prescribed for the AppleScript Utility. Thanks!
This is an excellent script thanks!
A nice addition to the script would be the ability to drop a folder into the watch folder, have the script recursively import items from the folder, and even possibly append the name of the dropped folder to the front of each item as it places the item into Evernote.
This could allow you to drop a folder named "Important Customer" into the the watch folder, and have all files imported as "Important Customer: Filename".
Thanks!
DAn
Stephen -
This is really a wonderful script -- very helpful. I've set it up to allow me to auto-import into evernote from a Canon printer, which I wasn't otherwise able to do (I can if I initiate the scan from my computer, but not from the buttons on the scanner). For that purpose, though, it'd be even better if it'd prompt for a file name (or even an Evernote item name). Any suggestions for how to accomplish that? (My applescript skills are limited to cutting and pasting, and even that is often touch and go.) Thanks!
Ben - glad you like the script.
Okay first of all you can get some user input by adding in some lines like this (say after the 'tell application evernote' line)...
display dialog "Please enter a note title:" default answer "New note"set NoteTitle to text returned of result
This will capture a note title from the user and pop it into a variable called NoteTitle.
You can then amend the create note from file line to the following...
create note from file item_path notebook "Auto Import" title NoteTitleYou can add more scripting in to handle defaulting the note title to the filename (rather than "New Note" or at least mention the name in the prompt text in case you're importing multiple files), to ask for tags (which would be ideal for Dan's suggestion I reckon if you made 'Important Customer' the tag) or even for different notebooks.
Hope that helps and inspires, or at the very least doesn't confuse matters.
Stephen.
Stephen,
Great script! So useful! As a newbie to Applescript, though, I'm not sure how to add the different dialogs you referenced in your last comment. I'd love to be able to add a prompt for tags (or notebooks), but I'm not sure how to get Applescript to translate that into actually adding tags (or notebooks) to Evernote. Is there a reference guide somewhere for the different Evernote-specific Applescript commands?
Thanks!
Celeste.
Glad you like the script.
Here's what the alterations for Ben might look like if you wanted to capture a note's title and then the tags for the note. If multiple tags are used, these could be separated by commas.
display dialog "Please enter a note title:" default answer "New note"
set NoteTitle to text returned of result
set AppleScript's text item delimiters to ","
display dialog "Please enter tags separated by a comma:" default answer ""
set NoteTags to text returned of result
The line of script to include the tags might then look like the one below.
create note from file item_path notebook "Auto Import" title NoteTitle tags NoteTags
You might want to tidy this up to gracefully deal with no tags being given by not trying to create the note with tags.
The details about the use of "create note" can be found in the Evernote AppleScript dictionary. In the AppleScript editor, select File > Open Dictionary... from the menu. Locate Evernote.app in the list and this wil load the documentation dictionary. If you search through you should find all the syntax and details about creating a new Evernote note in the "create note" section.
I hope that helps.
Stephen.
I can't get the script to work or see the recommended screencast. I have a folder named "Dell" that i want sync'd automatically with my Evernote DELL folder. all it does is beep, no folder, nofiles :(
Hi! I was referred to your script by Evernote. I followed the instructions as best I could but nothing seems to work. I tried the automator instructions and I tried the script instructions (I'm using Lion on a MacBook Air and I couldn't find my library so I put the script into the main library on the root). I'm coming from Windows so am a total know-nothing about Mac yet. Is there anything else I should try? Thanks. Floyd
Jeff.
Sorry you're having problems with the script. I'm not sure exactly what screencast you're referring to, but I'll do my best to help.
First of all this isn't a synchronisation script. The script (when attached to a folder) keeps watching the folder and when one or more files is copied/moved to the folder it adds them into Evernote into separate notes. If you remove the files it will not remove the notes from Evernote, neither will any change in Evernote be cascaded back to the folder.
You say you get a beep so it suggests the script is running. the first thing i would suggest is checking that you have set "Auto Import" to be "Dell" or whatever the name is of the Notebook you have created in Evernote. If the notebook does not exist then the script can't add the files into notes.
The next thing to check is that you're copying in files that are able to be imported into Evernote. Too big or requiring or a file type that you don't have permission (premium accounts allows you to import any file type) to import could be an issue.
After that you probably want to use something like
display dialog item_pathto debug what's going on - e.g. display the name of each file being imported as the script runs.Have a dig about, see what you find. Let us know what this throws up.
Floyd.
I think the not finding the library folder is a Lion thing. By default Apple now hide it. If you open the Go menu in Finder and press and hold the ALT key, you should see an option for Library "Apple magically" appear.
Anyway, it sounds like the library you put the script in is the right place. Within the "Library" folder on the root of the drive, there is a "Scripts" folder. Within that is a "Folder Action Scripts". This is where your script file (.scpt) should be placed.
Find the folder you want to have run the action when files are put into it. Right click on the folder and select "Folder Actions Set-up..." from the "Services" sub-menu. This will open up the Folder Actions setting window. On the left pane click the + and then select your folder. In the right pane (with your folder selected ont he left), click the + and then you should see your script in the list. Select it, close the window and that should be it done.
Let me know how you get on with this.