Skip to content

Instantly share code, notes, and snippets.

@fractaledmind
Last active December 20, 2015 03:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fractaledmind/6068092 to your computer and use it in GitHub Desktop.
Save fractaledmind/6068092 to your computer and use it in GitHub Desktop.
This script will insert 3 notes at the top of your open Skim PDF. These notes contain linking information that is used in the EXPORT ALL SKIM NOTES script.
(* GENERATE 3 INITIAL SKIM NOTES WITH LINKING INFO (CUSTOM URL VERSION)
-- created by Stephen Margheim
-- 13 July 2013
-- open source
REQUIRED PROGRAMS:
-- Skim
This script requires setting up the custom URL handler described [here](http://hackademic.postach.io/page/create-a-custom-url-scheme-for-free).
It will insert 3 notes at the top of your current PDF. Simply open the PDF in Skim and run the app/script. The 3 generated notes contain linking information used in the Export Skim Notes script.
* Note 1 includes the custom URL and the pdf's title.
* Note 2 includes a Markdown formatted link
* Note 3 includes a field to be filled depending on the relation of the printed page numbers and the Skim-based page numbers.
*)
tell application "Skim"
set theFile to file of document 1 as string
set theHome to path to home folder as string
set theFilePath to my replaceString(theFile, theHome, "")
set pdfPath to my encode_text(theFilePath, true, false)
set pdfPath to my replaceString(pdfPath, ":", "/")
set customurl to "customurl://com.hackademic.AppleScript.URL_Handler?action=1$" & pdfPath & "#"
set PdfName to name of document 1
set docPath to path of front document
set notesPath to text 1 thru -5 of docPath & " (notes).skim"
--save the document and its notes as-is
save front document
save front document in notesPath
delete notes of front document
--create the three opening notes
tell page 1 of document 1
make note with properties {type:anchored note, bounds:{523, 760, 540, 760}, text:customurl, extended text:PdfName}
delay 0.1
make note with properties {type:anchored note, bounds:{523, 780, 540, 780}, text:"[" & PdfName & "](" & customurl}
delay 0.1
make note with properties {type:anchored note, bounds:{523, 760, 540, 760}, text:"0", extended text:"[change to appropriate number: (1) IF skim p# = printed p# --> 0 (2) IF skim p# > printed p# --> pr# - sk# (3) IF random printed p# --> ra# - 1 (if also FrontPage, ra# - 2)]"}
end tell
--return any previously existing notes
read notes front document from notesPath without replacing
end tell
(* SUB-ROUTINES *)
on encode_text(this_text, encode_URL_A, encode_URL_B)
set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
set the URL_B_chars to ".-_:"
set the acceptable_characters to the standard_characters
if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
set the encoded_text to ""
repeat with this_char in this_text
if this_char is in the acceptable_characters then
set the encoded_text to (the encoded_text & this_char)
else
set the encoded_text to (the encoded_text & encode_char(this_char)) as string
end if
end repeat
return the encoded_text
end encode_text
on encode_char(this_char)
set the ASCII_num to (the ASCII number this_char)
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set x to item ((ASCII_num div 16) + 1) of the hex_list
set y to item ((ASCII_num mod 16) + 1) of the hex_list
return ("%" & x & y) as string
end encode_char
on replaceString(theText, oldString, newString)
-- ljr (http://applescript.bratis-lover.net/library/string/)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replaceString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment