Jump to content
Join the #EverBetterChallenge and finish what you start in 2019. Read more... ×
victor50

Evernote auto-import folder for Mac OS X

Recommended Posts

In many occasions I have to scan a document and, unfortunately, I have to manually create a note in Evernote with that file as an attachment.

I know that with Evernote for Mac OS X cannot define a folder to automatically import newly created files from (this instead is possible with Evernote for MS-windows).

I've just finished writing an applescript code (called "EvernoteNewNoteFromFile.scpt"; see attachment) acting as an "Action Folder Script" that is it automatically starts as soon as a new file is created/moved into a specific folder.

When this script is fired it creates a new note with a title, one (and only one) tag and attaches the file in the "automatic" folder to the note.

When the script starts it asks the user only for a title and one (and only one) tag and automatically attaches the folder-newly-added file to the new EN note.

To use this script you should:

1) Create the (not-yet automatic) folder

2) Copy EvernoteNewNoteFromFile.scpt into your home Library/Scripts/Folder Action Scripts (to go to Library click on Go in the Finder menu while pressing the Option/Alt key);

3) Open with the applescript editor EvernoteNewNoteFromFile.scpt and only modify the line:

set MyNotebook to "Vittorio"

with your notebook name. Save and close;

4) In Finder go to the not-yet automatic folder you've just created, right-click on it, and from the menu choose "Services->Folder Actions Setup" and combine the folder with EvernoteNewNoteFromFile.scpt.

Now, your folder is an automatic folder that fires the script when a new file is added.

That's all folk

Ciao from Rome, Vittorio

Share this post


Link to post

where do we go to get the script in the first place? also, I don't find a "Scripts" folder within my "library" folder? Is it different in mountain lion? I do see an "application scripts" folder, is that it?

Thanks.

Share this post


Link to post

Well, I attached the file EvernoteNewNoteFromFile.scpt to my message but now I see that this file cannot be attached. Something went wrong!

Anyway, here is the code of the same script that you should copy and past into the applescript editor, modifiy set MyNotebook to "Vittorio" as I said:

---------------------------------------

--

-- Created by: Vittorio De Martino

-- Created on: 09/27/12 15:39:27

--

--

on adding folder items to theFolder after receiving theNewItems

-- Called after items have been added to a folder

--

-- theFolder is a reference to the modified folder

-- theNewItems is a list of references to the items added to the folder

set myfile to (get info for item 1 of theNewItems)

set DestFile to (theFolder as string) & (name of myfile) as alias

(*SET YOUR NOTEBOOK*)

set MyNotebook to "Vittorio"

tell application "Evernote"

activate

set listOfTags to {}

set EVTags to every tag --GET THE TAGS LIST

repeat with currentTag in EVTags

set currentTagName to (the name of currentTag)

copy currentTagName to the end of listOfTags

end repeat

(*SORT THE TAGs LIST VIA BUBBLE SORT*)

set last_swap_position to length of listOfTags

repeat while last_swap_position is greater than 0

set comparisons_needed to last_swap_position - 1

set last_swap_position to 0

repeat with i from 1 to comparisons_needed

if item i of listOfTags > item (i + 1) of listOfTags then

set swap_item to item i of listOfTags

set item i of listOfTags ¬

to item (i + 1) of listOfTags

set item (i + 1) of listOfTags to swap_item

set last_swap_position to i

end if

end repeat

end repeat

(*SET THE TITLE OF YOUR NOTE*)

display dialog "Title of your note" default answer ""

set MyTitle to the text returned of the result

(*USER SELECTION FROM TAGs LIST *)

set SelTag to choose from list of listOfTags with title "Select Tag" with prompt ¬

"Available Evernote Tags" OK button name "OK"

set EVtag to item 1 of SelTag

create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

tags EVtag attachments (DestFile as alias)

end tell

end adding folder items to

-------------------------------------------------------

As far as Library/Scripts/Folder Action Scripts is concerned, well, this is where I found it under 10.7 Lion. I don't know where they put it under Mountain Lion.

  • Like 1

Share this post


Link to post

Thanks for posting the script directly into this post. I got it working, but even though I have a pretty new quad core macbook pro it takes a really long time to run. Has that been your experience as well? once I drop a file in, it waits about 45-90 seconds, the fan spins up on my machine and then finally the dialog box pops up. Wouldn't think it would take some much computing power to run this fairly simple script. Thoughts?

Thanks again! :)

Well, I attached the file EvernoteNewNoteFromFile.scpt to my message but now I see that this file cannot be attached. Something went wrong!

Anyway, here is the code of the same script that you should copy and past into the applescript editor, modifiy setMyNotebookto "Vittorio" as I said:

---------------------------------------

--

-- Created by: Vittorio De Martino

-- Created on: 09/27/12 15:39:27

--

--

on adding folder items to theFolder after receiving theNewItems

-- Called after items have been added to a folder

--

-- theFolder is a reference to the modified folder

-- theNewItems is a list of references to the items added to the folder

set myfile to (get info for item 1 of theNewItems)

set DestFile to (theFolder as string) & (name of myfile) as alias

(*SET YOUR NOTEBOOK*)

set MyNotebook to "Vittorio"

tell application "Evernote"

activate

set listOfTags to {}

set EVTags to every tag --GET THE TAGS LIST

repeat with currentTag in EVTags

set currentTagName to (the name of currentTag)

copy currentTagName to the end of listOfTags

end repeat

(*SORT THE TAGs LIST VIA BUBBLE SORT*)

set last_swap_position to length of listOfTags

repeat while last_swap_position is greater than 0

set comparisons_needed to last_swap_position - 1

set last_swap_position to 0

repeat with i from 1 to comparisons_needed

if item i of listOfTags > item (i + 1) of listOfTags then

set swap_item to item i of listOfTags

set item i of listOfTags ¬

to item (i + 1) of listOfTags

set item (i + 1) of listOfTags to swap_item

set last_swap_position to i

end if

end repeat

end repeat

(*SET THE TITLE OF YOUR NOTE*)

display dialog "Title of your note" default answer ""

set MyTitle to the text returned of the result

(*USER SELECTION FROM TAGs LIST *)

set SelTag to choose from list of listOfTags with title "Select Tag" with prompt ¬

"Available Evernote Tags" OK button name "OK"

set EVtag to item 1 of SelTag

create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

tags EVtag attachments (DestFile as alias)

end tell

end adding folder items to

-------------------------------------------------------

As far as Library/Scripts/Folder Action Scripts is concerned, well, this is where I found it under 10.7 Lion. I don't know where they put it under Mountain Lion.

Share this post


Link to post

Thanks for posting the script directly into this post. I got it working, but even though I have a pretty new quad core macbook pro it takes a really long time to run. Has that been your experience as well? once I drop a file in, it waits about 45-90 seconds, the fan spins up on my machine and then finally the dialog box pops up. Wouldn't think it would take some much computing power to run this fairly simple script. Thoughts?

Absolutely no! With my old (2008) dual core white macbook using Lion it takes about 15 sec to arrive at the first request of the title when a new file is added and above all when the script has to start EN from scratch.

Instead If EN is already active is a matter of seconds.

Have you checked that EvernoteNewNoteFromFile.scpt is the only script to be fired when a new file is added?

Share this post


Link to post

I noticed that the attached file in the new note is duplicated. To correct this, please substitute the line (see toward the end of code):

create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

tags EVtag attachments (DestFile as alias)

with

create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

tags EVtag

Share this post


Link to post

Hi Victor50,

your scripts run very well.

I also use evernote for windows and the Import folder command creates a note automaticaly with the name of the files. I need something like this: i want that Evernote create a note automaticaly taking the name of the file and, if possibile, always the same tags automaticaly.

Can we do that in your scripts modifyng something?

thank you

Share this post


Link to post

Hi Victor50,

your scripts run very well.

I also use evernote for windows and the Import folder command creates a note automaticaly with the name of the files. I need something like this: i want that Evernote create a note automaticaly taking the name of the file and, if possibile, always the same tags automaticaly.

Can we do that in your scripts modifyng something?

thank you

Well, I've only hacked my original script and here it is what I think you want (remember to modify EVTag and MyNotebook according to your needs). It's by far simpler than the original case!

Ciao from Rome, Italy

--

-- Created by: Vittorio De Martino

-- Created on: 11/27/12 15:39:27

--

--

on adding folder items to theFolder after receiving theNewItems

-- Called after items have been added to a folder

--

-- theFolder is a reference to the modified folder

-- theNewItems is a list of references to the items added to the folder

set myfile to (get info for item 1 of theNewItems)

set DestFile to (theFolder as string) & (name of myfile) as alias

set MyTitle to (name of myfile)

--

-- PUT HERE YOUR WANTED TAG

set EVtag to "Filemaker"

(*SET YOUR NOTEBOOK*)

set MyNotebook to "Vittorio"

tell application "Evernote"

activate

-- create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

-- tags EVtag attachments (DestFile as alias)

create note from file (DestFile as alias) title MyTitle notebook MyNotebook ¬

tags EVtag

end tell

end adding folder items to

Share this post


Link to post

Hi everyone,

I was searching the net for a script such as this one. While doing so, I also ran across this script (made in 2010):

http://www.thoughtasylum.com/blog/2010/5/11/evernote-watched-folders-on-os-x.html

Might anyone be able to comment which is the better script (better for me would be, faster, easier to manipulate options, efficient code, etc)...if I don't get a response I'll simply test it myself, but hopefully someone might already have experience with both?

Thanks for the script Victor!

Share this post


Link to post

It is a great script and I have got it working in Lion, so thanks. But the simplest way to get stuff onto Evernote is just drag n drop to the Evernote icon in the dock. Over the years I have learned to always try drag n drop on the mac before I try anything else.

Share this post


Link to post

Hi - I modified the script a little bit.

  1. To use with Hazel
  2. To add functionality to select tags from a list (allows multiple selections)
  3. To implement the traditional quickSort rather than the very slow bubble sort

I have tested on my Evernote library with hundreds of tags and it is really fast. See how you go !


-- start the Hazel script

on hazelProcessFile(theFile)

-- add to Evernote
addToEvernote(theFile)
end hazelProcessFile

--quickSort function

on quickSort(theList)
--http://macscripter.net/viewtopic.php?id=24766
--public routine, called from your script
script bs
property alist : theList

on Qsort(leftIndex, rightIndex)
--private routine called by quickSort.
--do not call from your script!
if rightIndex > leftIndex then
set pivot to ((rightIndex - leftIndex) div 2) + leftIndex
set newPivot to Qpartition(leftIndex, rightIndex, pivot)
set theList to Qsort(leftIndex, newPivot - 1)
set theList to Qsort(newPivot + 1, rightIndex)
end if

end Qsort

on Qpartition(leftIndex, rightIndex, pivot)
--private routine called by quickSort.
--do not call from your script!
set pivotValue to item pivot of bs's alist
set temp to item pivot of bs's alist
set item pivot of bs's alist to item rightIndex of bs's alist
set item rightIndex of bs's alist to temp
set tempIndex to leftIndex
repeat with pointer from leftIndex to (rightIndex - 1)
if item pointer of bs's alist ≤ pivotValue then
set temp to item pointer of bs's alist
set item pointer of bs's alist to item tempIndex of bs's alist
set item tempIndex of bs's alist to temp
set tempIndex to tempIndex + 1
end if
end repeat
set temp to item rightIndex of bs's alist
set item rightIndex of bs's alist to item tempIndex of bs's alist
set item tempIndex of bs's alist to temp

return tempIndex
end Qpartition

end script

if length of bs's alist > 1 then bs's Qsort(1, length of bs's alist)
return bs's alist
end quickSort

-- addToEvernote function

on addToEvernote(aFile)
tell application "Evernote"
activate

set listOfNotebooks to {}
set theNotebooks to every notebook
repeat with currentNotebook in theNotebooks
set currentNotebookName to (the name of currentNotebook)
copy currentNotebookName to the end of listOfNotebooks
end repeat

set listOfTags to {}
set theTags to every tag
repeat with currentTag in theTags
set currentTagName to (the name of currentTag)
copy currentTagName to the end of listOfTags
end repeat

my quickSort(listOfNotebooks)
my quickSort(listOfTags)

display dialog "Evernote title" default answer "Title"
set theTitle to the text returned of the result

set selectedNotebook to choose from list of listOfNotebooks with title "Select a Notebook" with prompt "Evernote Notebooks" OK button name "OK"
set selectedTags to choose from list of listOfTags with title "Select Tags (multiple allowed)" with prompt "Evernote Tags" OK button name "OK" with multiple selections allowed
set theNotebook to item 1 of selectedNotebook

create note from file aFile title theTitle notebook theNotebook tags selectedTags

end tell

end addToEvernote

Share this post


Link to post

This is the latest version that includes the ability to create new tags and also new notebooks:

 

-- start the Hazel scripton hazelProcessFile(theFile)	-- add to Evernote	addToEvernote(theFile)end hazelProcessFileon quickSort(theList)	--http://macscripter.net/viewtopic.php?id=24766	--public routine, called from your script	script bs		property alist : theList				on Qsort(leftIndex, rightIndex)			--private routine called by quickSort. 			--do not call from your script!			if rightIndex > leftIndex then				set pivot to ((rightIndex - leftIndex) div 2) + leftIndex				set newPivot to Qpartition(leftIndex, rightIndex, pivot)				set theList to Qsort(leftIndex, newPivot - 1)				set theList to Qsort(newPivot + 1, rightIndex)			end if					end Qsort				on Qpartition(leftIndex, rightIndex, pivot)			--private routine called by quickSort. 			--do not call from your script!			set pivotValue to item pivot of bs's alist			set temp to item pivot of bs's alist			set item pivot of bs's alist to item rightIndex of bs's alist			set item rightIndex of bs's alist to temp			set tempIndex to leftIndex			repeat with pointer from leftIndex to (rightIndex - 1)				if item pointer of bs's alist ≤ pivotValue then					set temp to item pointer of bs's alist					set item pointer of bs's alist to item tempIndex of bs's alist					set item tempIndex of bs's alist to temp					set tempIndex to tempIndex + 1				end if			end repeat			set temp to item rightIndex of bs's alist			set item rightIndex of bs's alist to item tempIndex of bs's alist			set item tempIndex of bs's alist to temp						return tempIndex		end Qpartition			end script		if length of bs's alist > 1 then bs's Qsort(1, length of bs's alist)	return bs's alistend quickSorton addToEvernote(aFile)	tell application "Finder"		-- check if we should be excluding thsi file		if ((label index of aFile) = 3) or ((label index of aFile) = 2) then			display dialog ("The file " & aFile as string) & " has been excluded, import into Evernote manually and delete source file" buttons {"Quit"}			return 1		end if	end tell	tell application "Evernote"		activate				set listOfNotebooks to {}		set theNotebooks to every notebook		repeat with currentNotebook in theNotebooks			set currentNotebookName to (the name of currentNotebook)			copy currentNotebookName to the end of listOfNotebooks		end repeat				set listOfTags to {}		set theTags to every tag		repeat with currentTag in theTags			set currentTagName to (the name of currentTag)			copy currentTagName to the end of listOfTags		end repeat				my quickSort(listOfNotebooks)		my quickSort(listOfTags)				set question to display dialog "Evernote title" default answer "Note Title" buttons {"OK", "Quit"} default button 1		set theButton to button returned of question		set theTitle to the text returned of question				if theButton is equal to "Quit" then			tell application "Finder"				set label index of aFile to 3			end tell			return 1		end if				set question to display dialog "Import PDF into which Evernote notebook?" buttons {"Existing", "Create New", "Quit"} default button 1		set answer to button returned of question				if answer is equal to "Existing" then			--display the list			set selectedNotebook to choose from list of listOfNotebooks with title "Select a Notebook" with prompt "Evernote Notebooks" OK button name "OK"		else if answer is equal to "Create New" then			--create new evernote notebook			display dialog "Enter new notebook name" default answer "notebook"			set theNoteBookName to the text returned of the result						try				set selectedNotebook to create notebook theNoteBookName with type synchronized			on error				display dialog "Error creating Evernote notebook" buttons {"Quit"}				tell application "Finder"					set label index of aFile to 2				end tell				return 1			end try		else if answer is equal to "Quit" then			--exit script and delete PDF			tell application "Finder"				set label index of aFile to 3			end tell			return 1		end if				set selectedTags to (choose from list of listOfTags with title "Select Tags (multiple allowed)" with prompt "Your Evernote Tag List" with multiple selections allowed and empty selection allowed)		if selectedTags is false then			tell application "Finder"				set label index of aFile to 3			end tell			return 1		end if				if (count selectedTags) = 0 then			set tagQuestion to display dialog "Enter a list of new tags" default answer "comma, seperated, tag, list, multi word tags, can have spaces"			set theNewTagString to the text returned of tagQuestion			set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}			set selectedTags to text items of theNewTagString -- Gives list {"tag1", "tag2", "tag3"}			set AppleScript's text item delimiters to myTID -- It's considered good practice to return the TID's to their original state		end if				-- list choice returns a list so grab first element		set theNotebook to item 1 of selectedNotebook				try			create note from file aFile title theTitle notebook theNotebook tags selectedTags		on error			display dialog "Could not create Evernote note" buttons {"Quit"}			tell application "Finder"				set label index of aFile to 2			end tell			return 1		end try	end tell	end addToEvernote-- replaced this function with code aboveon addToEvernoteOLD(aFile)	tell application "Evernote"		activate				set listOfNotebooks to {}		set theNotebooks to every notebook		repeat with currentNotebook in theNotebooks			set currentNotebookName to (the name of currentNotebook)			copy currentNotebookName to the end of listOfNotebooks		end repeat				set listOfTags to {}		set theTags to every tag		repeat with currentTag in theTags			set currentTagName to (the name of currentTag)			copy currentTagName to the end of listOfTags		end repeat				my quickSort(listOfNotebooks)		my quickSort(listOfTags)				display dialog "Evernote title" default answer "Title"		set theTitle to the text returned of the result				set selectedNotebook to choose from list of listOfNotebooks with title "Select a Notebook" with prompt "Evernote Notebooks" OK button name "OK"		set selectedTags to choose from list of listOfTags with title "Select Tags (multiple allowed)" with prompt "Evernote Tags" OK button name "OK" with multiple selections allowed		set theNotebook to item 1 of selectedNotebook				create note from file aFile title theTitle notebook theNotebook tags selectedTags			end tell	end addToEvernoteOLD

Share this post


Link to post
ilium007,

 

Thanks for sharing your script. I am unable to make it work, is there somethng I missed?

 

I copy&paste in AppleScriptEditor.

Saved it in "Mac HD>Library>Scripts>Folder Action Scripts"

Enable it with "Folder Action Setup..." on my download folder

 

and nothing - it does not do anything. I have tried with other scripts before and no problem.

 

I appreciate your comments.

Share this post


Link to post

It is a Hazel script. To use with folder actions you will need to change this call to the function to suit:

-- start the Hazel script

on hazelProcessFile(theFile)

-- add to Evernote

addToEvernote(theFile)

end hazelProcessFile

I don't have a Mac with me at present so I can't give you the code to use.

Share this post


Link to post

ilium007,

 

I just installed the trial version of Hazel and ran your script. Some feedback:

 

a. Extremely fast and functional. The best that I have tried so far.

 

b. A problem that USD 25 are needed for Hazel. A normal Folder Action Script would be very good.

 

 

Suggestions:

 

1. I think that having the filename as the default title will be practical, the current default is "Note Title".

 

2. In addition to to "Existing" and "Create New " options I would add "Default Notebook". Most of my notes go to the default notebook.

 

3. In the tag list It does not allow for an untagged note. Not all my notes are tagged, actually they are the least. Again an option "No tag" will speed up the process.

 

Thanks again.

Share this post


Link to post

Sure - at $100 an hour I can do anything for you !!

 

Seriously though, just look at the code and modify it to suite your needs. $25 is nothing really when you consider how powerfull Hazel is - just buy it and go to the movies one less time this year.

  • Like 1

Share this post


Link to post

illum007 that looks like a great script, and just what I'm after. Hazel is a great tool, and I use it all the time.

 

However, I can't get Hazel to accept the script. This is a new rule I'm attempting to add:

 

post-86219-0-23088700-1366287374_thumb.p

 

I've pasted your script in embedded script, but it won't save it, complaining about the first "on" statement. Do you have any ideas what I'm doing wrong?

Share this post


Link to post

illum007 that looks like a great script, and just what I'm after. Hazel is a great tool, and I use it all the time.

However, I can't get Hazel to accept the script. This is a new rule I'm attempting to add:

Screen Shot 2013-04-18 at 13.13.56.PNG

I've pasted your script in embedded script, but it won't save it, complaining about the first "on" statement. Do you have any ideas what I'm doing wrong?

The script would need to be modified slightly to use as an 'embedded script' in Hazel. You might be better to open AppleScript Editor and save as a .scpt file and then reference the file from Hazel. That's how I do it.

Share this post


Link to post

The script would need to be modified slightly to use as an 'embedded script' in Hazel. You might be better to open AppleScript Editor and save as a .scpt file and then reference the file from Hazel. That's how I do it.

 

 

 

 

 

Thanks, illum007, that explains it.

Share this post


Link to post

Hey, this is great! I really needed something like this.

 

However, I want to slightly modify the code so the default note title is set to the filename. How is this done?

 

Thanks!

Share this post


Link to post

This is just what I was looking for! Thank you! One note: I could not save the script directly to the Folder Action Scripts folder. I had to first save to the desktop and then move it to that folder, and enter my Mac OS administrator password. After that, no problems!

Share this post


Link to post

My Applescript has just stopped running for no reason I know of. I have tried making a new AppleScript from Vittorio's most recent posted script in this thread and I have tried placing the script in Automator. But nothing happens when I save a file in my Evernote Auto-import folder. I wonder if anyone else has experienced this.  I am on Os X 10.8.5 and Evernote 5.4.1.

 

Very frustrating.

Share this post


Link to post

I took @ilium007's excellent script and modified it to be "hands free". I didn't need for it to prompt for notebook or name or tags - I just wanted to have files added to a folder automatically added as notes. No dialogs unless there's an error.

 

Here's the stripped back code:

-- start the Hazel scripton hazelProcessFile(theFile)	-- add to Evernote	addToEvernote(theFile)end hazelProcessFileon addToEvernote(aFile)	tell application "Evernote"		activate				try			create note from file aFile title "Voice Memo" notebook "brain dump"		on error			display dialog "Could not create Evernote note" buttons {"Quit"}			tell application "Finder"				set label index of aFile to 2			end tell			return 1		end try			end tell	end addToEvernote

You will want to edit the line which starts "create note..." to the title and notebook of your choosing.

 

If it wasn't clear how to use this with Hazel, here's how:

 

1. save the script to a file somewhere (location not important)

2. open Hazel prefs and add the folder where you will be dumping the files you want added to Evernote

3. create a rule: choose "any file" in the "If" condition, and choose "Run AppleScript" in the "Do the following.." section and point it at the script

 

Et voila! Any time you add a file to that folder, Hazel will run the script and create a note.

Share this post


Link to post

Ellemef, you figured out how to do something I've wanted for over a year but couldn't find until today! Super excited to put Hazel to good use! 

Share this post


Link to post

@ellemef - How would I append a timestamp to the file title ("Voice Memo" in your example), given that I can create such a timestamp with something like:

 

set curDate to do shell script "date +'%Y-%m-%d-%H-%M-%S'"

Share this post


Link to post

... and even better - to get the title of the note ("Voice Memo" in your example) to be the first N characters of the file that's added !  ?

Share this post


Link to post

×