You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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:

User uploaded file

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)

Posted on May 11, 2015 9:08 PM

Reply
6 replies

May 11, 2015 11:23 PM in response to yinsdianao

It's hard to tell since I don't have Skim, but the nature of the error message and the screenshot make me think this is a simple problem - it's just one of line breaks.


If you copied the script from a web site, the chances are the web browser wrapped long lines to fit on the screen, and when you pasted that into the Script Editor it no longer made sense as a script.


Specifically, the line:


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”})

should be all one line, but in your screenshot, 'Results' has been wrapped to a new line. While there are ways of creating multi-line/wrapped statements in the script editor, the simplest solution may be to remove the leading space before "Results" and bring that onto the preceding line - and also look for other similar cases that might have wrapped.

Let me know if that works. There may still be other issues with the script.

May 12, 2015 8:37 AM in response to Jacques Rioux

Thanks Jacques. That WAS the problem for the syntax error code. I marked your reply as the answer. But if you (or anyone else) could help with the subsequent problem too, it would be great.


After making the punctuation changes, the error disappeared.


However, when I tried to run the script, I found that the color and categories ( 'summary of literature', etc) did not match as I expected - they were all over the place. I suspected it had to do with the last part of the code. Please see the screenshot comparing the original script (left) and my customized script (right), as well as their corresponding color schemes.


I find that for the original script, the functional phrases 'colorCodes', 'noteColor', 'then', 'else if', etc are all in a unique font style (green or bold). But for my customized script, the first 3 sets are not similarly styled. This indicates a problem?. But then again I am not sure how I should solve it.


Note that I did not manually bold or apply color to the rest of the script - it automatically happened after the syntax error was resolved.


Thanks.


User uploaded file

May 12, 2015 12:43 PM in response to yinsdianao

Hi,



There are still wrong punctuation in your script.




the script after 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"

is a long string , this syntax is OK, but this skip the first three conditions.


Here is the corrected script

----

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

------



If these substitutions occurs in the Script Editor :

right click on the editor --> Select "Substitutions" --> "Show Substitutions" , and uncheck the "Smart quotes" case.

Applescript to export Skim notes by color

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.