Skip to content

Instantly share code, notes, and snippets.

@dougtoppin
Last active August 29, 2015 14:12
Show Gist options
  • Save dougtoppin/6acfef254c0a718760ba to your computer and use it in GitHub Desktop.
Save dougtoppin/6acfef254c0a718760ba to your computer and use it in GitHub Desktop.
AppleScript script to read a text file and import each line as a note into Evernote
(*
example of using AppleScript to read a text file with 4 tab delimited fields in it, echo each field in each line and then send that
entry as a new note into Evernote in the notebook called ImportedNotes
Field 1 is just a record number and is not inserted into the note
Field 2 is treated as an Evernote tag (will also be tagged with 'imported_from_notes')
Field 3 is the text of the note
Field 4 is a timestamp in the format of mm/dd/yyyy, the note creation and modification dates will be set to this
example input lines (tabs between each field):
1 field2 field3 10/12/2009
2 field2 field3 10/22/2009
Some of how this was done was found at this link https://discussion.evernote.com/topic/4046-importing-from-apple-mailapps-notes/page-2
*)
set myfile to "notes2.txt" -- input file
set tid to AppleScript's text item delimiters -- preserve initial text delimiters
set allRecords to read myfile using delimiter linefeed -- read file
repeat with aRecord in allRecords -- iterate on each line read from file
if length of aRecord is greater than 0 then -- ignore null lines
set text item delimiters to tab -- prepare to parse line using tab
set theTextItems to text items of aRecord -- parse line into fields
set AppleScript's text item delimiters to tid -- restore text delimiters
log "item number: " & item 1 of theTextItems
log " tag: " & item 2 of theTextItems
log " item text: " & item 3 of theTextItems
log " item timestamp: " & item 4 of theTextItems
set theDate to item 4 of theTextItems
tell application "Evernote"
set myNote to create note with text item 2 of theTextItems title item 2 of theTextItems notebook "ImportedNotes" tags ["imported_from_notes", item 2 of theTextItems]
set the HTML content of myNote to item 3 of theTextItems
set the creation date of myNote to (date theDate)
set the modification date of myNote to (date theDate)
end tell
end if
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment