Export Skim notes according to their highlight colors

Adam Cronkright mentioned, in a thread in the Skim forum, that he uses different colors for highlighting various sections of a PDF, which have a common characteristic (e.g. author’s points he agrees with, points he disagrees with, good phrases…). His problem is that he would like to have an efficient way to organize these different categories of notes and Skim’s present features does not help him much to this end.I think that a way to solve this problem is to use a specialized app for note management and an AppleScript, which exports Skim notes according to their color. So I found a reason to write an additional AppleScript or actually two!The first is a simplified version, which has only one prerequisite for execution. Particularly, you need to use one or more of the following colors: ice, honey drew, flora, lemon, cantaloupe, silver, which are shown below.

You can change a color in the Favorite Colors by dragging a new color from the Color Panel (Tools> Show Colors) and drop it on the Favorite Colors toolbar item. Hold down the Option key to add a new color. You can remove a color from the Favorite Colors by dragging it to the Trash (from Tips and Tricks page in Skim’s wiki).

Each color in Skim is represented as a list of four numbers (red, green, blue, alpha). The fourth number is constant (65535). For example, the ice color is represented by the list  {26214, 65535, 65535, 65535}. So you can change the hardwired colors in the scripts if you know the corresponding RGB (red, green, blue) code in 16-bit format for your preferred colors. Then you can add it in in the chooseColor subroutine (see the AppleScript below).

When you execute the script the following windows will open consecutively:

You can choose more than one colors by pressing cmd + click.

If you choose “Some” then you will be asked to give the range of pages from which the notes will be extracted.

 

The result is sent to the clipboard.

The second AppleScript is that which I use and is quite more complicated. As you may know, my preferred program for managing notes is MediaWiki so the AppleScript’s result is customized for import in a MediaWiki page.

Some additional features of this AppleScript are the following:

  • a hyperlink to the exact PDF page is created for each exported note
  • the annotation’s date and time are added at the end of each exported note
  • the notes from each page are separated by a line
  • the extended text of the note is exported as well
  • the first five notes of the first page are not exported
  • the written page numbers should be given in the dialog windows

If you want to use this AppleScript you need firstly to create the five Skim notes in the first PDF page as I describe in my post “How to create correctly the Skim notes which have the DEVONthink links, when you have already annotated the first page of the PDF document.

The code is the following:

I hope this AppleScript will help Adam! Anyway, your post was an inspiration for me. Finally, I would like to thank Martin who informed me about it.

6 Responses to “Export Skim notes according to their highlight colors”

  1. gj says:

    Hey there,

    Found your site today and your scripts seem to be very very useful for me :-) I’ve modded the simple on you provided here so that it won’t ask anything anymore. I’ve set the default highlighting color in Skim to “honeydew” and now the script just copies all my notes to the clipboard.

    THought it might help someone else get some insight, as I’, just hacking and trying myself here. So I posted the code, if you don;t mind

    Code:
    — untitled.applescript

    — Created by gerben jan on 2011-12-01.
    — Copyright (c) 2011 __MyCompanyName__. All rights reserved.

    –2011-06-10
    –http://organognosi.blogspot.com/
    tell application “Skim”
    set the clipboard to “”
    set numberOfPages to count pages of document 1
    activate
    –gehackt om de lemon vraag niet meer te krijgen
    set myColorCodes to my chooseColor()

    set firstPage to “1” as number
    set lastPage to numberOfPages
    set the clipboard to “Skim notes” & 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 noteText to get text for coloredNote

    set the clipboard to (the clipboard) & noteText & return & return
    end if
    end repeat
    end repeat

    end tell
    end exportPageNotes

    on chooseColor()

    set colorCodes to {}
    set noteColor to “”
    set end of colorCodes to {52428, 65535, 26214, 65535}
    return colorCodes
    end chooseColor

    –Color codes:
    –“ice” {26214, 65535, 65535, 65535}
    –“honey drew” {52428, 65535, 26214, 65535}
    –“flora” {26214, 65535, 26214, 65535}
    — “lemon” {65535, 65535, 2, 65535}
    — “cantaloupe” {65535, 52428, 26214, 65535}
    –“silver” {52428, 52428, 52428, 65535}

  2. ovitch says:

    Hi,

    The script sounds great but I don’t understand the color definition. I can find the native RGBA from the color but not in the format you specified colors.

    Could you give me a hint on how you defined these colors, even in Skim?

    Thanks in advance

  3. Stephen says:

    John,

    Loved the script. Put it to good use for a while, but recently was working on a pdf book (600 pages) and the script was lagging. Also, I like to take text notes as well as I read pdfs, but these are not exported with this script. Because I love your work in general and this script specifically, I went to work to modify it. Below I have my script which will export every type Skim note FAST. I write everything in Markdown, so Markdown syntax is used, but it’s a minor detail.
    The key difference is that I dropped the Repeat Call; instead, I merely query Skim for every note and go from there.

    Like I said, I’m a big-fan. Your blog has been an immense help and inspiration for my thought and writing at http://hackademic.postach.io/.

    Here’s the script:

    tell application “Skim”
    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
    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
    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 number_of_Note3 to (get text of note 3 of page 1 of document 1) as string
    set LF to ASCII character 10
    set FinalText to “”
    repeat with i from 1 to count of selNotes_types
    set notePage to itemi of selNotes_pages
    set DEVONpage to notePage – 1
    set DEVONpage_text to DEVONpage as text
    set theRealPage to notePage + number_of_Note3 as string
    if item i of selNotes_types is text note then
    set noteText to itemi of selNotes_text
    set noteTitle to “NB”
    set titleText to “My Text Note”
    set FinalText to FinalText & “” & noteTitle & “: ” & LF & Markdownlink & DEVONpage_text & “): ” & LF & “” & titleText & “: ” & noteText & ” (p.” & theRealPage & “)” & LF & LF
    else if item i of selNotes_types is anchored note then
    set noteTitle to itemi of selNotes_text
    set noteText to extended text of itemi of selNotes
    set titleText to “My Anchor Note”
    set FinalText to FinalText & “” & noteTitle & “: ” & LF & Markdownlink & DEVONpage_text & “): ” & LF & “” & titleText & “: ” & noteText & ” (p.” & theRealPage & “)” & LF & LF
    end if
    end repeat
    repeat with i from 1 to count of selNotes_types
    set notePage to itemi of selNotes_pages
    set DEVONpage to notePage – 1
    set DEVONpage_text to DEVONpage as text
    set theRealPage to notePage + number_of_Note3 as string
    if item i of selNotes_types is underline note then
    set noteText to itemi of selNotes_text
    set noteTitle to “”
    set titleText to “Underlined Text”
    set FinalText to FinalText & “” & titleText & “: ” & LF & Markdownlink & DEVONpage_text & “): ” & LF & “\”” & noteText & “\”” & ” (p.” & theRealPage & “)” & LF & LF
    else if item i of selNotes_types is strike out note then
    set noteText to itemi of selNotes_text
    set noteTitle to “”
    set titleText to “Stike-Through Text”
    set FinalText to FinalText & “” & titleText & “: ” & LF & Markdownlink & DEVONpage_text & “): ” & LF & “\”” & noteText & ” (p.” & theRealPage & “)” & “\”” & LF & LF
    else if item i of selNotes_types is highlight note then
    set theColor to color of itemi of selNotes
    set titleText to my color2text(theColor)
    set noteText to itemi of selNotes_text
    set noteTitle to “”
    set FinalText to FinalText & “” & titleText & “: ” & LF & Markdownlink & DEVONpage_text & “): ” & LF & “\”” & noteText & “\”” & ” (p.” & theRealPage & “)” & LF & LF
    end if
    end repeat
    tell application “TextMate”
    insert FinalText
    end tell

    (* If you don’t have TextMate, here’s the script for the universal Mac program TextEdit. To alter the code, merely delete or comment-out the TextMate tellblock and uncomment this block: *)
    — tell application “TextEdit”
    — activate
    — make new word at end of text of document 1 with data FinalText
    — end tell

    end tell

    on color2text(noteColor)
    set colorText to {}
    if noteColor is {64634, 900, 1905, 65535} then
    set end of colorText to “Summary”
    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 “Disagree”
    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
    return colorText
    end color2text

Leave a Reply