Откройте редактор AppleScript и сохраните этот скрипт как /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
Затем запустите defaults write /Applications/skimnoteopener.app/Contents/Info.plist CFBundleURLTypes '({CFBundleURLName=skimnoteopener;CFBundleURLSchemes=(skimnoteopener);})'
. Приложение должно быть немедленно зарегистрировано как обработчик по умолчанию для схемы URL.
Затем вы можете использовать этот скрипт для экспорта заметок:
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
Скрипт копирует заметки как форматированный текст. Вы можете сохранить заметки в файле rtf, заменив -stdout|LC_CTYPE=UTF-8 pbcopy
на -output /path/to/file.rtf
.
Вот еще один скрипт, который копирует текст, выбранный в Skim в качестве ссылки:
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"