Export all pdf notes at once

I already have jekyll serving markdown files. So, I thought what if I could also add my skim (a MAC pdf reader) notes to it. After searching and going through skim sourceforge wiki, I collected this script to do this.

First we have to change the default skim template for text files. So open up the templates directory for skim using vi ~/Library/Application\ Support/Skim/Templates/notesTemplate.txt and add the following skim template

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
---
title: "<$fileName.lastPathComponent.stringByDeletingPathExtension/>"
source: "<$fileURL/>"
---

<$notes.@arraySortedByPageIndexAndBounds>
[<$modificationDate/>](<$skimURL/>)

<$string?>
- <$string/>

</$string?>
<$text?>
- <$text/>

</$text?>
</$notes.@arraySortedByPageIndexAndBounds>

Next save the following command as a bash script. Replace pdf folder and notes folder with appropriate paths.

find "~/Documents/PdfFolder/" -not -name '.*' -name "*.pdf" -type f -execdir sh -c '/usr/local/bin/skimnotes get -format text "{}" "~/NotesDirectory/{}.md"' \;

Let's break down the script. The find command goes through every pdf file in the selected folder in this case being ~/Documents/PdfFolder/ and then it executes in the directory (-execdir) of the pdf file the command sh -c '/usr/local/bin/skimnotes get -format text "{}" "~/NotesDirectory/{}.md"'. This command tells skimnotes to export the pdf notes in "~/NotesDirectory/ folder in text format. Note the {}, this is replaced by pdf name.

Its all done. All your pdf notes are now in markdown files with url for the specific notes. Now, all that's left is to create a script to format the exported notes file. I will post it later.

NOTE: You will have to resave your pdf files before exporting as skim saves the pdf with default template files.