Blog

2 Articles

Import Papers notes into Evernote (Mac)

Papers is a great application for reading, organizing, and citing academic papers. The iOS version syncs with the desktop so I can read papers on my iPad. But Papers is not where I keep my notes; that’s Evernote’s job! So I’ve written a script to export my Papers notes into Evernote.

It takes a paper like this, with highlights, comments, and tags:

Papers 3.4.6ScreenSnapz006

And creates an Evernote note like this:

EvernoteScreenSnapz012

The paper’s general comment is at the beginning of the note in italics, followed by a link back to the paper in Papers and the abstract. The notes and comments section has highlighted text in normal font and in-text comments bolded. Page numbers are according to the “pages” field in the paper’s metadata.

Many papers, such as those from JStor, have a title page before the paper begins. To get correct page numbering the script needs to adjust the page numbers exported by Papers. When you run the script it asks for a “page increment.” For most papers this should be 0: no adjustment needed. For papers with a title page, it should be -1.

To install the script you can download it here: Papers notes to Evernote (and unzip), or cut-and-paste the source below into Apple’s Script Editor. Either way, place the script in an appropriate folder (I use /Users/michaelthicke/Library/Scripts/Applications/Papers). Then you can run it from the script menu with Papers open and a paper selected. It will import the selected paper into Evernote.

Papers 3.4.6ScreenSnapz005

Source:

--Script to export notes of selected Papers paper to Evernote with nice formatting.
--Exports General Note, Papers link, highlights, and notes.
--Mike Thicke, Aug 2016

use framework "Foundation"
use scripting additions

--export the selected file to a temporary file
tell application id "com.mekentosj.papers3"
	set pubList to (selected publications of front library window) as list
	log pubList
	set thePublication to first item of pubList
	set itemLink to ("

Papers Link

" set itemAbstract to abstract of thePublication --deleted at end of script set outFile to ((path to desktop from user domain) as string) & "papersexporttemp001.txt" export {thePublication} as Notes to outFile --keywords set keywordsString to keyword names of thePublication if not keywordsString = "" then set keywordList to my theSplit(keywordsString, ",") else set keywordList to {} end if end tell --add a page increment to adjust for papers with title pages (eg. from JStor) display dialog "Number to offset each page number by (can be positive or negative)" default answer "0" set textIncrement to text returned of result set numberIncrement to textIncrement as integer --open notes file tell application "System Events" set notesFile to (outFile as text) set notesText to read file (notesFile) as «class utf8» end tell --title of Evernote note is citation of paper set noteTitle to paragraph 1 of notesText set noteTitle to my replacePattern("< .*>", noteTitle, "") --capture General Note section set generalNoteText to "" set pNum to 2 repeat set noteCheckText to my replacePattern("^p.[0-9]*: .*", (paragraph pNum of notesText), "found") if noteCheckText = "found" then set generalNoteText to generalNoteText & "" exit repeat else set generalNoteText to generalNoteText & "

" & (paragraph pNum of notesText) & "

" set pNum to pNum + 1 end if end repeat --remove paragraphs of noteText containing citation and General Note set newText to "" repeat with i from pNum to (count paragraphs of notesText) set newText to newText & paragraph i of notesText & " " end repeat set notesText to newText --remove excess spaces set notesText to my replacePattern("( )+", notesText, " ") --break notes and comments into chunks --uses ❄︎ as delimiter because comments can be multiple paragraphs and so can't just split on paragraph breaks set notesText to my replacePattern("(?ms)(p.[0-9].+?)($?)(.*?(Highlighted|Written).*?)[0-9]{4}", notesText, "$1$3❄︎") set notesArray to theSplit(notesText, "❄︎") --abstract set abstractHTML to "

Abstract

" & itemAbstract & "

" --will be used to create new note set final_html to generalNoteText & itemLink & abstractHTML & "

Notes and Comments

" --construct html list from notesArray repeat with noteItem in notesArray set pageNumber to my replacePattern("(?ms)^\\s*p.([0-9]+).*", noteItem, "$1") if (not pageNumber = "") and (not pageNumber = noteItem) then try set pageNumber to (pageNumber as integer) + textIncrement --highlights are normal list items set noteItem to my replacePattern("(?ms)^(\\s*p.[0-9]*:) (.*).--.Highlighted.*?$", noteItem, "
  • $2 (" & pageNumber & ")
  • ") --comments in bold set noteItem to my replacePattern("(?ms)^(\\s*p.[0-9]*:) (.*).--.Written.*?$", noteItem, "
  • $2 (" & pageNumber & ")
  • ") on error errormessage set pageNumber to 0 end try set final_html to final_html & noteItem end if end repeat --create a new note with noteTitle as title and final_html as content tell application "Evernote" if not final_html = "" then --new notes put in General Research folder if (not (notebook named "General Research" exists)) then create notebook "General Research" end if set my_notebook to notebook named "General Research" set new_note to create note title noteTitle with html final_html --keywords set end of keywordList to "papers notes" repeat with theKeyword in keywordList set theKeyword to my replacePattern("^\\s*(.+?)\\s*$", theKeyword, "$1") try set my_tag to make tag with properties {name:theKeyword} on error errormessage set my_tag to tag named theKeyword end try assign my_tag to new_note end repeat move new_note to my_notebook open note window with new_note tell application "System Events" to set frontmost of process "Evernote" to true end if end tell tell application "System Events" delete alias outFile end tell --http://macscripter.net/viewtopic.php?pid=168800 on replacePattern(thePattern, inString, usingThis) set theRegEx to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:0 |error|:(missing value) set theResult to theRegEx's stringByReplacingMatchesInString:inString options:0 range:{location:0, |length|:length of inString} withTemplate:usingThis return theResult as text end replacePattern --http://erikslab.com/2007/08/31/applescript-how-to-split-a-string/ on theSplit(theString, theDelimiter) log theString -- save delimiters to restore old settings set oldDelimiters to AppleScript's text item delimiters -- set delimiters to delimiter to be used set AppleScript's text item delimiters to theDelimiter -- create the array set theArray to every text item of theString -- restore the old setting set AppleScript's text item delimiters to oldDelimiters -- return the result return theArray end theSplit

    Importing Kindle notes to Evernote (for Mac)

    At some point in my graduate student career I realized that if I don’t have organized, electronic, searchable notes for everything that I read, I might as well not have read it at all. I picked Nagel’s The Structure of Science off my bookshelf the other day and discovered that I’d read, underlined, and scribbled notes on a pretty substantial portion of it, and all I have from that experience is a vague remembrance of his comparison between science and common sense. Maybe I’ve internalized some of Nagel’s writing into my understanding of science in some non-specific way, but that doesn’t do me much good when I’m trying to cite examples or evidence relevant to my research.

    So these days I do essentially 100% of my academic reading electronically, whether it is through PDFs or on Kindle. However, having highlights and notes in a Kindle document is only marginally more useful than having them on my bookshelf. But through a magical bookmarklet called Bookcision and a little script I wrote, I can import my highlights and notes into Evernote, where they’re searchable and copyable. Plus, every note comes with a clickable link that takes me back to its source.

    Here’s how it looks in Evernote: