Applescript to export Skim notes by color
Hi,
I am not sure if this is the appropriate place to post my question. It involves a 3rd party app - Skim - that is used by many in the academia (and elsewhere) to read and annotate PDF files. Also, I must state that I have no knowledge about applescript whatsoever. I was looking for a particular feature for this software and came upon a website where an applescript was posted. I tried editing it to suit my needs. However, it looks like I made some mistake and I am basically looking for help to correct the script. Below are further details:
So Skim is a freeware for reading and annotating PDFs. One of the things that many people do when reading PDFs is to highlight sentences and parts. They might use different colors to indicate different purposes for highlighting. For example, you might use red highlight for parts that you disagree with, and you might use green to for parts that you want to use in your paper, etc. What I was looking for was a way to export the Skim notes sorted by different highlight colors (and their corresponding categories).
I came upon this website that posted an applescript solution:
http://jones.kaist.edu/notebook/2012/09/an-academic-notetaking-workflow.html
Their original code is posted at the very bottom.
The script worked. However, I wanted to make some changes. Namely, I wanted to add more categories (n=9; for the original script n=6: 'summary', 'result', 'technique'. etc). Also, I wanted different colors to correspond to the categories. So, I made some changes to the parts pertaining to color codes, and my customized code is posted below.
However, apparently I made a mistake (or several/many mistakes) because a box (see screenshot posted below the customized script) popped up stating: 'Syntax Error: Expected “,” or “}” but found identifier.' The part "Results" is highlighted. As I do not have any knowledge about applescripts (or programming in general), I could not quite figure out what is the problem.
Would it be too much trouble if anyone takes a look and perhaps let me know how to edit the script to make it work?
Attempt at customization:
tell application "Skim"
set the clipboard to ""
set numberOfPages to count pages of document 1
activate
set myColorCodes to my chooseColor()
set firstPage to "1" as number
set lastPage to numberOfPages
set the clipboard to "# Notes #" & return & return
repeat with currentPage from firstPage to lastPage
set pageNotes to notes of page currentPage of document 1
exportPageNotes(pageNotes, currentPage, myColorCodes) of me
end repeat
end tell
on exportPageNotes(listOfNotes, pageForProcessing, myColorCodes)
tell application "Skim"
set currentPDFpage to pageForProcessing
repeat with coloredNote in listOfNotes
repeat with i from 1 to the count of myColorCodes
if color of coloredNote is item i of myColorCodes then
set categoryColors to ({"Summary of Literature”, ”General Notes“, ”Future Directions“, ”Interpretation and Discussion of Results”, ”Techniques”,"Results”, "References to Check”, “Research Question or Hypothesis", “Definition or Quotes”})
set noteColor to color of coloredNote as string
if noteColor is item i of myColorCodes as string then
set noteColor to item i of categoryColors
end if
set noteText to get text for coloredNote
set the clipboard to (the clipboard) & "**[" & noteColor & "]" & "(skimmer://" & name of document 1 & "#page=" & pageForProcessing & ")**" & ": " & return & noteText & return & return
end if
end repeat
end repeat
end tell
end exportPageNotes
on chooseColor()
set selectedColors to ({"Summary of Literature”, ”General Notes“, ”Future Directions“, ”Interpretation and Discussion of Results”, ”Techniques”, "Results”, "References to Check”, “Research Question or Hypothesis", “Definition or Quotes”})
set colorCodes to {}
set noteColor to ""
repeat with noteCol in selectedColors
set noteColor to noteCol as text
if noteColor is "Summary of Literature” then
set end of colorCodes to {64907, 32785, 2154, 65535}
else if noteColor is “General Notes” then
set end of colorCodes to {65535, 65531, 2689, 65535}
else if noteColor is “Future Directions“ then
set end of colorCodes to {39321, 26214, 13107, 65535}
else if noteColor is "Interpretation and Discussion of Results" then
set end of colorCodes to {32768, 0, 32768, 65535}
else if noteColor is "Techniques" then
set end of colorCodes to {64634, 467, 1798, 65535}
else if noteColor is "Results" then
set end of colorCodes to {64587, 609, 65481, 65535}
else if noteColor is "References to Check" then
set end of colorCodes to {7, 115, 65418, 65535}
else if noteColor is "Research Question or Hypothesis" then
set end of colorCodes to {8372, 65519, 65472, 65535}
else if noteColor is "Definition or Quotes" then
set end of colorCodes to {8608, 65514, 1548, 65535}
end if
end repeat
return colorCodes
end chooseColor
Error:
Original applescript from website:
tell application "Skim"
set the clipboard to ""
set numberOfPages to count pages of document 1
activate
set myColorCodes to my chooseColor()
set firstPage to "1" as number
set lastPage to numberOfPages
set the clipboard to "# Notes #" & return & return
repeat with currentPage from firstPage to lastPage
set pageNotes to notes of page currentPage of document 1
exportPageNotes(pageNotes, currentPage, myColorCodes) of me
end repeat
end tell
on exportPageNotes(listOfNotes, pageForProcessing, myColorCodes)
tell application "Skim"
set currentPDFpage to pageForProcessing
repeat with coloredNote in listOfNotes
repeat with i from 1 to the count of myColorCodes
if color of coloredNote is item i of myColorCodes then
set categoryColors to ({"Summary", "Technique", "Result", "Reference", "Hypothesis", "Question or connection"})
set noteColor to color of coloredNote as string
if noteColor is item i of myColorCodes as string then
set noteColor to item i of categoryColors
end if
set noteText to get text for coloredNote
set the clipboard to (the clipboard) & "**[" & noteColor & "]" & "(skimmer://" & name of document 1 & "#page=" & pageForProcessing & ")**" & ": " & return & noteText & return & return
end if
end repeat
end repeat
end tell
end exportPageNotes
on chooseColor()
set selectedColors to ({"Summary", "Technique", "Result", "Reference", "Hypothesis", "Question or connection"})
set colorCodes to {}
set noteColor to ""
repeat with noteCol in selectedColors
set noteColor to noteCol as text
if noteColor is "Summary" then
set end of colorCodes to {64634, 900, 1905, 65535}
else if noteColor is "Technique" then
set end of colorCodes to {64907, 32785, 2154, 65535}
else if noteColor is "Result" then
set end of colorCodes to {65535, 65531, 2689, 65535}
else if noteColor is "Reference" then
set end of colorCodes to {8608, 65514, 1753, 65535}
else if noteColor is "Hypothesis" then
set end of colorCodes to {8372, 65519, 65472, 65535}
else if noteColor is "Question or connection" then
set end of colorCodes to {64587, 1044, 65481, 65535}
end if
end repeat
return colorCodes
end chooseColor
MacBook Air (13-inch, Early 2014), OS X Yosemite (10.10)