I wrote a complete applescript program that save the notes to a "sidecar file" and it also register this file to Calibre so it doesn't get lost. You can save the script in the Skim script library /Users/<username>/Library/Skim/Scripts
=====
(*
Save skim Notes to Calibre and Close
Skim script, written by Alessandro Piovaccari
ABOUT
This script save PDF annotations added with Skim in a separate skim file in the same folder of the .pdf
If the .skim format is not registered in Calibre for that entry, then it adds it to the database.
HISTORY
- 2015-01-17 – v1.0; first working version
KNOWN ISSUES
- File names that start with "_" can create a problem.
- If filename contains "_" than only the part of the filename till "_" is matched (short title)
This happens when the title has illegal filename characters that get substituted by "_"
- There could be a problem if there are 2 title with the same short title
TO DO
- Should check for file existance and ask for overwrite confirmation
- Skim format should be added only if format has not been register before
- Improve the filename matching
- I could add a confirmation before registering (skim file is saved correctly as it is at the same path of the PDF)
*)
--Set these to the correct path (these are for default installation)
set calibreCmd to "/usr/bin/calibredb"
set awkCmd to "/usr/bin/awk"
tell application "Skim"
activate
set filepathPdf to path of front document
end tell
set filepathSkim to Unicode text 1 thru -5 of (filepathPdf as Unicode text) & ".skim"
tell application "Skim"
save front document in filepathSkim as "Skim Notes"
close front document without saving
end tell
set file_info to the info for filepathPdf
set file_name to the name of file_info
--Get the title of the book
set titleOffset to (offset of " - " in file_name) - 1
set bookTitle to (text 1 thru titleOffset of file_name)
set undscrOffset to (offset of "_" in bookTitle) - 1
if undscrOffset > 1 then
set bookTitleShort to (text 1 thru undscrOffset of bookTitle)
else
set bookTitleShort to bookTitle
end if
--display alert bookTitle
--display alert bookTitleShort
--Get the author of the book
set authorOffset to titleOffset + 4
set bookAuthor to (text authorOffset thru -5 of file_name)
--display alert bookAuthor
--Determine the Calibre library path
set libraryOffset to (offset of bookAuthor in filepathPdf) - 2
set bookLibrary to (text 1 thru libraryOffset of filepathPdf)
--display alert bookLibrary
--Get the book record
--set calibreSearchCmd to calibreCmd & " list --library-path \"" & bookLibrary & "\" --separator=\";\" --search='author:\"" & bookAuthor & "\"' | grep " & (quoted form of bookTitleShort)
--set bookRecord to (do shell script calibreSearchCmd)
--display alert bookRecord
--Get the book ID
--The matching is done by doing a calibredb search per author and then the line with matched "short" title is considered the recors
--There could be a problem if there are 2 title with the same short form
--I could add a confirmation before registering (skim file is saved correctly as it is at the same path of the PDF)
set calibreSearchIdCmd to calibreCmd & " list --library-path \"" & bookLibrary & "\" --separator=\";\" --search='author:\"" & bookAuthor & "\"' | grep " & (quoted form of bookTitleShort) & " | " & awkCmd & " -F \";\" '{print $1}'"
set bookId to (do shell script calibreSearchIdCmd)
--display alert bookId
--add the format
set calibreAddFormatCmd to calibreCmd & " add_format --library-path \"" & bookLibrary & "\" " & bookId & " " & (quoted form of filepathSkim)
try
do shell script calibreAddFormatCmd
on error
display alert "Something went wront wile adding the .skim format to Calibre."
end try
Last edited by piovac; 10-23-2015 at 06:51 PM.
|