What I've done to accomplish this is to use Mac's Applescript and I pieced together a hacky, but workable, way to do just this. It's not entirely pretty, and I'm sure it could be done better, but it does work with one caveat and some instructions (it's unfortunately not an entirely automatic procedure). So here it is for anyone else who wants an already working way to do the same thing.
First off, the caveat: The very first note imported into Evernote ends up being an HTML attachment, instead of the text. And the formatting gets a little bit screwy in the imported files, but in my opinion, that's acceptable since what I want is to have this information for future reference.
- Create a new directory, this will be your input directory, and export the notebooks from RedNotebook you want imported as HTML. This will create one large XML file for all the notes for each notebook you want imported.
- Create a new directory, this will be your output directory, and save this file to it. This file is the top portion of the xml file that will make up each of the individual notes in the evernote notes.
- Download the applescript or copy and paste from below to your computer.
- Run the script, you will be prompted for the following:
- The header file, which is the template file you downloaded to your output directory.
- The output directory you created.
- The input directory containing the html files form RedNotebook
- Once the script is done, it is necessary to manually open the first exported file in your export directory and copy and paste this into the first note imported in Evernote, as mentioned earlier.
- Creates a new notebook in Evernote with the same name as the HTML file it is importing. If you have multiple HTML files, it will create a new notebook for each of these files.
- For each HTML file, it will create a new note in the new notebook. The new note will be named the date the note was created and the creation date of the note will be modified to reflect this, so this metadata is not lost.
set listOfNames to {}
set fileTemplate to choose file with prompt "Select the template file"
set templateLines to paragraphs of (read fileTemplate)
set outputFolder to choose folder with prompt "Select the output folder"
set createDate to current date
set createFileName to ""
set filelist to my getFileList(choose folder with prompt "Select the source folder")
repeat with currentFile in filelist
set headerSkipped to false -- skip the RedNotebook header
set headerContents to false -- drop the content between the top of the file and the RedNotebook header
set newFileLines to {templateLines}
set listFileNames to {}
-- read all the lines in the file
set myLines to readFile(currentFile as alias)
repeat with nextLine in myLines
set startTagLoc to (offset of "" in nextLine)
if startTagLoc > 0 then -- found header tag
if not headerSkipped then
set headerSkipped to true -- skip the initial RedNotebook header
else
set commaLoc to (offset of "," in nextLine)
set endTagLoc to (offset of "
" in nextLine)
set dateString to text (commaLoc + 2) thru (endTagLoc - 1) of nextLine
-- set the create date and the filename to use
set createDate to my convertDate(dateString)
set createFileName to text (startTagLoc + 4) thru (endTagLoc - 1) of nextLine
set outputFileName to outputFolder & createFileName & ".html"
set listFileNames to listFileNames & outputFileName
if not headerContents then
set headerContents to true
else
if (count of newFileLines) > 0 then
my writeFile(newFileLines, outputFileName, currentFile, createDate, false)
my exportToEvernote(currentFile, outputFileName, createDate)
-- reset the list
set newFileLines to {templateLines}
end if
end if
end if
else
set newFileLines to newFileLines & nextLine
end if
headerSkipped
createDate
createFileName
end repeat
my writeFile(newFileLines, outputFileName, currentFile, createDate, true)
end repeat
on getFileList(inputFolder)
tell application "Finder"
set filelist to every file of the folder inputFolder
end tell
return filelist
end getFileList
on readFile(myFile)
tell application "Finder"
set myLines to paragraphs of (read myFile)
end tell
return myLines
end readFile
on convertDate(inputString)
return date (inputString)
end convertDate
on writeFile(newFileLines, newFileName, currentFile, createDate, isEof)
-- the following should actually be an end-div, end-body and end-html tags
set templateEnd to ""
set myFile to currentFile as alias
set finalText to {}
set end of finalText to newFileLines
set outFile to newFileName as text
if not isEof then
set finalText to finalText & templateEnd
end if
set AppleScript's text item delimiters to ASCII character 10
set myText to finalText as text
set AppleScript's text item delimiters to ""
set myFile to open for access outFile with write permission
write myText to myFile
close access myFile
return
end writeFile
on exportToEvernote(currentFile, newFileName, createDate)
set AppleScript's text item delimiters to ":"
set noteTitle to item 2 of newFileName
set notebookName to last text item of (currentFile as text)
set AppleScript's text item delimiters to ""
tell application "Evernote"
set theItem to create note title noteTitle created createDate notebook notebookName from file (newFileName as text)
end tell
return
end exportToEvernote
No comments:
Post a Comment