Script to export a list of notes from Evernote to a CSV file

Hi,

I am wondering if anyone knows of a script that would export a list of all the notes currently selected in Evernote (or alternatively all of the notes in a particular notebook) to a CSV file.

I am hoping that I could adapt such a script to my needs, which are as follows:

  1. Generate a CSV file with 4 values per row (1 row per note), namely 'Date,Price,Item,Tag"

  2. Each of my notes has a title in the format: “20110801 10.00 Note1” (i.e. date,price,item)

  3. So the first three values in the CSV file would be constructed from the title of the note with the date converted from the form 20110801 to 01/08/2011.

  4. The tag in the note would become the fourth value in the CSV file.

I’d be grateful for any help in writing such a script.

Thanks,

Nick

I never used EverNote but it seems that this one may do the trick.



--{code}
--[SCRIPT]

on run
	set mon_bloc_note to "AppleScriptNotebook1"
	if character 2 of (0.5 as text) is "." then
		set delim to ", "
	else
		set delim to "; "
	end if
	
	tell application "Evernote" to tell notebook mon_bloc_note
		set les_fiches to {}
		repeat with i from 1 to count of notes
			tell note i
				set la_fiche to my decoupe(get title, space)
				set la_date to item 1 of la_fiche
				set item 1 of la_fiche to (text -2 thru -1 of la_date) & "/" & (text -4 thru -3 of la_date) & "/" & (text 1 thru 4 of la_date)
				set les_tags to get tags
				set names_of_tags to {}
				repeat with un_tag in les_tags
					copy name of un_tag to end of names_of_tags
				end repeat
				copy my recolle(names_of_tags, "_") to end of la_fiche
				--set item 2 of la_fiche to quote & item 2 of la_fiche & quote
				copy my recolle(la_fiche, delim) to end of les_fiches
			end tell -- note i
		end repeat
	end tell -- Evernote
	
	set filePath to (path to desktop as text) & (do shell script "date +nickharambee_%Y%m%d_%H%M%S.csv")
	
	set theResult to writeTo(filePath, my recolle(les_fiches, return), text, false)
	if not theResult then display dialog "There was an error writing the data!"
end run

--=====

on decoupe(t, d)
	local oTIDs, l
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to d
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

--=====

on recolle(l, d)
	local oTIDs, t
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to d
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

--=====

on writeTo(targetFile, theData, dataType, apendData)
	(*
Handler by Regulus6633
in http://macscripter.net/viewtopic.php?id=36861
*)
	-- targetFile is the path to the file you want to write
	-- theData is the data you want in the file.
	-- dataType is the data type of theData and it can be text, list, record etc.
	-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
	try
		set targetFile to targetFile as text
		set openFile to open for access file targetFile with write permission
		if apendData is false then set eof of openFile to 0
		write theData to openFile starting at eof as dataType
		close access openFile
		return true
	on error
		try
			close access file targetFile
		end try
		return false
	end try
end writeTo

--[/SCRIPT]
--{code}

As you see, I borrowed a Regulus6633’s handler :wink:

Yvan KOENIG (VALLAURIS, France) mardi 23 août 2011 19:35:19