Created
September 7, 2013 23:15
-
-
Save fractaledmind/6480259 to your computer and use it in GitHub Desktop.
This script will (as the title suggests) export all of you Skim notes directly to Evernote with hyperlinks. It relies on the GENERATE TOP 3 NOTES WITH SYSTEM URL script that will put 3 notes at the top of the PDF with linking information. When launched, the script will ask you if the current PDF is a Primary Source or a Secondary Source. Your ch…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* PROPERTIES *) | |
property LF : (ASCII character 10) | |
property LF1 : (ASCII character 32) & (ASCII character 32) & (ASCII character 10) | |
property tid : AppleScript's text item delimiters | |
(* THE SCRIPT *) | |
tell application "Skim" | |
set theTextStatus to display dialog "Is the PDF a Primary or Secondary text?" buttons {"Primary", "Secondary"} default button {"Secondary"} | |
--get info for all notes | |
set allNotes to every note of document 1 | |
set allNotes_types to every type of notes of document 1 | |
set allNotes_text to text of every note of document 1 | |
set allNotes_pages to index of every page of every note of document 1 | |
--get info for all notes except top 3 | |
set selNotes to items 4 through -1 of allNotes | |
set selNotes_types to items 4 through -1 of allNotes_types | |
set selNotes_text to items 4 through -1 of allNotes_text | |
set selNotes_pages to items 4 through -1 of allNotes_pages | |
--get info from those top 3 notes | |
set Markdownlink to (get text of note 2 of page 1 of document 1) as string | |
set pdfTitle to (get extended text of note 1 of page 1 of document 1) as string | |
set PDFLink to (get text of note 1 of page 1 of document 1) as string | |
set number_of_Note3 to (get text of note 3 of page 1 of document 1) as string | |
--prepare Headers for all of the various note types | |
set notesText_text to "<hr />" & LF & LF & "<h2>The ToC</h2>" & LF1 & LF & LF | |
set notesText_anchor to "<hr />" & LF & LF & "<h2>All of my Text Notes</h2>" & LF1 & LF & LF | |
set notesText_highlight to "<hr />" & LF & LF & "<h2>All of the Highlighted Text </h2>" & LF1 & LF & LF | |
set notesText_underline to "<hr />" & LF & LF & "<h2>All of the Underlined Text</h2>" & LF1 & LF & LF | |
set notesText_strikethru to "<hr />" & LF & LF & "<h2>All of the Strike-Through Text</h2>" & LF1 & LF & LF | |
(* THE MEAT-N-POTATOES OF THE SCRIPT *) | |
repeat with i from 1 to count of selNotes_types | |
--prepare Skim page # and actual page # | |
set notePage to item i of selNotes_pages | |
set theRealPage to notePage + number_of_Note3 as string | |
--collect Text Notes | |
if item i of selNotes_types is text note then | |
set noteText to item i of selNotes_text | |
set notesText_text to notesText_text & "<p>" & noteText & " (<a href=\"" & PDFLink & notePage & "\">" & "p." & theRealPage & "</a>)" & LF & LF | |
--collect Anchor Notes | |
else if item i of selNotes_types is anchored note then | |
set titleText to item i of selNotes_text | |
set noteText to extended text of item i of selNotes | |
set notesText_anchor to notesText_anchor & "<p><strong>" & titleText & ":</strong> " & noteText & " (<a href=\"" & PDFLink & notePage & "\">p." & theRealPage & "</a>)" & LF & LF | |
--collect Underline Notes | |
else if item i of selNotes_types is underline note then | |
set noteText to item i of selNotes_text | |
set notesText_underline to notesText_underline & "<p>\"" & noteText & "\"" & " (<a href=\"" & PDFLink & notePage & "\">" & "p." & theRealPage & "</a>)" & LF & LF | |
--collect Strike-Thru Notes | |
else if item i of selNotes_types is strike out note then | |
set noteText to item i of selNotes_text | |
set notesText_strikethru to notesText_strikethru & "<p>\"" & noteText & "\"" & " (<a href=\"" & PDFLink & notePage & "\">" & "p." & theRealPage & "</a>)" & LF & LF | |
--collect Highlight Notes | |
else if item i of selNotes_types is highlight note then | |
set theColor to color of item i of selNotes | |
set titleText to my color2text(theColor, theTextStatus) | |
set noteText to item i of selNotes_text | |
set notesText_highlight to notesText_highlight & "<p><strong>" & titleText & ":</strong> " & LF1 & "\"" & noteText & "\"" & " (<a href=\"" & PDFLink & notePage & "\">p." & theRealPage & "</a>)" & LF & LF | |
end if | |
end repeat | |
--extract only the "Summary" highlight notes | |
set theSummary to {} | |
set theParas to paragraphs of notesText_highlight | |
repeat with i from 1 to count of theParas | |
if item i of theParas contains "<p><strong>Summary:" then | |
set theTitle to item i of theParas | |
set theText to item (i + 1) of theParas | |
set theSumm to theTitle & LF & theText & LF & LF | |
copy theSumm to the end of theSummary | |
end if | |
end repeat | |
--remove "Summary" highlight notes from collection of highlight notes | |
if (not (theSummary is {})) then | |
set SumText to theSummary as string | |
set SumList to paragraphs of SumText | |
set empty to {""} | |
set FinalSum to my cleanmyList(SumList, empty) | |
set HighList to paragraphs of notesText_highlight | |
set finalHighlights to my cleanmyList(HighList, FinalSum) | |
set AppleScript's text item delimiters to LF | |
set notesText_highlight to (finalHighlights as string) | |
set theSummary to "<hr />" & LF & LF & "<h2>Text Summary</h2>" & LF1 & LF & LF & SumText | |
end if | |
--ALWAYS RETURN TEXT ITEM DELIMITERS TO NORMAL | |
set AppleScript's text item delimiters to tid | |
--remove any note sections that are empty | |
set FinalList to my textCheck(notesText_text, notesText_anchor, notesText_highlight, notesText_underline, notesText_strikethru, theSummary) | |
--prepare the final collection of notes, with MetaData | |
set FinalText to FinalList | |
--create new Evernote note | |
tell application "Evernote" | |
--create new "notes" tag if necessary | |
if (not (tag named "notes" exists)) then | |
set theTag to make tag with properties {name:"notes"} | |
else | |
set theTag to tag "notes" | |
end if | |
--create new "PDF Notes" notebook if necessary | |
if (not (notebook named "PDF Notes" exists)) then | |
make notebook with properties {name:"PDF Notes"} | |
end if | |
set theTitle to "Notes: " & pdfTitle | |
set newNote to create note title theTitle with html FinalText notebook "PDF Notes" | |
assign theTag to newNote | |
end tell | |
end tell | |
(* HANDLERS *) | |
--convert highlights into text values | |
on color2text(noteColor, theTextStatus) | |
set colorText to {} | |
if theTextStatus is {button returned:"Secondary"} then | |
if noteColor is {64634, 900, 1905, 65535} then | |
set end of colorText to "Disagree" | |
else if noteColor is {64907, 32785, 2154, 65535} then | |
set end of colorText to "Agree" | |
else if noteColor is {65535, 65531, 2689, 65535} then | |
set end of colorText to "Summary" | |
else if noteColor is {8608, 65514, 1753, 65535} then | |
set end of colorText to "Reference" | |
else if noteColor is {8372, 65519, 65472, 65535} then | |
set end of colorText to "Quotable" | |
else if noteColor is {64587, 1044, 65481, 65535} then | |
set end of colorText to "Technique" | |
end if | |
else if theTextStatus is {button returned:"Primary"} then | |
if noteColor is {64634, 900, 1905, 65535} then | |
set end of colorText to "Key Quote" | |
else if noteColor is {64907, 32785, 2154, 65535} then | |
set end of colorText to "Key Theme" | |
else if noteColor is {65535, 65531, 2689, 65535} then | |
set end of colorText to "Summary Passage" | |
else if noteColor is {8608, 65514, 1753, 65535} then | |
set end of colorText to "Key Motif" | |
else if noteColor is {8372, 65519, 65472, 65535} then | |
set end of colorText to "Confusing Passage" | |
else if noteColor is {64587, 1044, 65481, 65535} then | |
set end of colorText to "\"Purple\" Passage" | |
end if | |
end if | |
return colorText | |
end color2text | |
--generate random link IDs | |
on randomize(theVal) | |
set theAlphabet to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} | |
set randomLetter to random number from 1 to 26 | |
set randomLetter to item randomLetter of theAlphabet | |
set theNum1 to random number from 1 to 9 | |
set theNum2 to random number from 1 to 9 | |
set LinkID to theVal & theNum1 & theNum2 & randomLetter | |
return LinkID | |
end randomize | |
--remove any empty note sections | |
on textCheck(notesText_text, notesText_anchor, notesText_highlight, notesText_underline, notesText_strikethru, theSummary) | |
if notesText_text is "<hr /> | |
<h2>The ToC</h2> | |
" then | |
set notesText_text to "" | |
else | |
set notesText_text to notesText_text & LF & LF | |
end if | |
if notesText_anchor is "<hr /> | |
<h2>All of my Text Notes</h2> | |
" then | |
set notesText_anchor to "" | |
else | |
set notesText_anchor to notesText_anchor & LF & LF | |
end if | |
if notesText_highlight is "<hr /> | |
<h2>All of the Highlighted Text </h2> | |
" then | |
set notesText_highlight to "" | |
else | |
set notesText_highlight to notesText_highlight & LF & LF | |
end if | |
if notesText_underline is "<hr /> | |
<h2>All of the Underlined Text</h2> | |
" then | |
set notesText_underline to "" | |
else | |
set notesText_underline to notesText_underline & LF & LF | |
end if | |
if notesText_strikethru is "<hr /> | |
<h2>All of the Strike-Through Text</h2> | |
" then | |
set notesText_strikethru to "" | |
else | |
set notesText_strikethru to notesText_strikethru & LF & LF | |
end if | |
if theSummary is {} then | |
set theSummary to "" | |
else | |
set theSummary to theSummary & LF & LF | |
end if | |
return notesText_text & theSummary & notesText_anchor & notesText_highlight & notesText_underline & notesText_strikethru | |
end textCheck | |
--remove items from a list | |
on cleanmyList(theList, itemsToDelete) | |
set cleanList to {} | |
repeat with i from 1 to count theList | |
if {theList's item i} is not in itemsToDelete then set cleanList's end to theList's item i | |
end repeat | |
return cleanList | |
end cleanmyList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment