Open AppleScript Editor and save this script as /Applications/skimnoteopener.app:
on open location u
set text item delimiters to {"=", "&"}
do shell script "x=" & quoted form of text item 2 of u & ";printf \"${x//\\%/\\x}\""
set f to POSIX file result
set p to (text item 4 of u as integer)
set s to (text item 6 of u as integer)
set e to (text item 8 of u as integer)
tell application "Skim"
open f
tell document 1
set current page to page p
set selection to characters s thru e of text of page p
end tell
activate
end tell
end open location
Then run defaults write /Applications/skimnoteopener.app/Contents/Info.plist CFBundleURLTypes '({CFBundleURLName=skimnoteopener;CFBundleURLSchemes=(skimnoteopener);})'
. The application should be registered as the default handler for the URL scheme immediately.
You can then use this script to export highlight notes:
do shell script "osascript -e 'tell application \"Skim\"
selection of (notes of document 1 where (its type is highlight note))
end'|tr , \\\\n|awk '{print $2,$4}'"
set ranges to paragraphs of result
set out to ""
tell application "Skim"
set f to do shell script "ruby -e 'print ARGV[0].gsub(/[^A-Za-z0-9]/){\"%%%02X\"%$&.ord}' " & quoted form of POSIX path of (get file of document 1)
set i to 1
repeat with n in (notes of document 1 where (its type is highlight note))
set {s, e} to words of item i of ranges
set p to index of page of n
set out to out & "<a href=skimnoteopener://?file=" & f & "&page=" & p & "&start=" & s & "&end=" & e
set out to out & ">" & p & "</a> " & my escapexml(text of n) & "<br>" & linefeed
set i to i + 1
end repeat
end tell
do shell script "printf %s " & quoted form of out & "|textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"
on replace(input, search, replace)
set text item delimiters to search
set ti to text items of input
set text item delimiters to replace
ti as text
end replace
on escapexml(input)
replace(replace(replace(input, "&", "&"), "<", "<"), ">", ">")
end escapexml
The script copies the notes as rich text. You can save the notes to an rtf file by replacing -stdout|LC_CTYPE=UTF-8 pbcopy
with -output /path/to/file.rtf
.
Here is another script that copies the text selected in Skim as a link:
tell application "Skim"
set f to POSIX path of (get file of document 1)
set p to index of current page of document 1
set t to selection of document 1 as text
end tell
tell (do shell script "osascript -e 'tell app \"Skim\" to selection of document 1'")
set s to word 2
set e to word 4
end tell
do shell script "printf %s \"<a href=skimnoteopener://?file=$(ruby -e 'print ARGV[0].gsub(/[^A-Za-z0-9]/){\"%%%02X\"%$&.ord}' " & quoted form of f & ")&page=" & p & "&start=" & s & "&end=" & e & ">$(printf %s " & quoted form of t & "|sed 's/&/\\&/g;s/</\\</g;s/>/\\>/g')</a>\"|textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"