Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derickfay/e357c148c257618548a41389ef87b7ad to your computer and use it in GitHub Desktop.
Save derickfay/e357c148c257618548a41389ef87b7ad to your computer and use it in GitHub Desktop.
(* EXPORT ALL SKIM NOTES TO THE CLIPBOARD WITH MARKDOWN REFERENCE LINKS
(no longer) requires hackademic URL handler from github user smargh
entirely rewritten to take advantage of Skim's built-in templating
2016-06-26 by derickfay
*)
property LF : (ASCII character 10)
(* Skim Export Templates *)
set tNote to "<$contents?><$contents/></$contents?>"
set tPage to "<$page.label?><$page.label/><?$page.label?><$pageIndex.numberByAddingOne/></$page.label?>"
set tType to "<$type.typeName/>"
set tHeader to "<$fileURL/>"
set excludedTypes to {"Line", "Circle", "Square", "Ink"}
tell application "Skim"
try
convert notes front document
save front document
on error msg
return msg & " in Pre-Processing."
end try
-- get info from top 3 notes
try
set Markdownlink to (get text of note 2 of page 1 of document 1) as string
set pdfTitle to (get extended text of note 1 of page 1 of document 1) as string
set PDFLink to (get text of note 1 of page 1 of document 1) as string
set number_of_Note3 to (get text of note 3 of page 1 of document 1) as string
on error msg
set fail to button returned of (display dialog "Can't read top 3 notes" buttons {"Cancel", "Add Top 3 Notes"})
if fail is "Cancel" then
return
else
tell application "Alfred 3" to search "sk3"
end if
end try
set noteString to ""
set theHeader to "# Skim Notes: [" & pdfTitle & "](" & (format document 1 using template tHeader & ")" & LF & LF)
-- set refListText to LF & LF & "## Reference URLS:" & LF & LF
set refListText to ""
set allNotes to notes of document 1
-- adding sort to fix error introduced in recent versions of Skim
repeat with i from 1 to (count of allNotes) - 1
repeat with j from i + 1 to count of allNotes
if index of page of item j of allNotes < index of page of item i of allNotes then
set temp to item i of allNotes
set item i of allNotes to item j of allNotes
set item j of allNotes to temp
end if
-- log allNotes
end repeat
end repeat
set activeNotes to items 4 through -1 of allNotes
repeat with n in activeNotes
set noteType to format n using template tType
if noteType is not in excludedTypes then
set formattedNote to format n using template tNote
set correctedPage to ((format n using template tPage) as integer) + number_of_Note3
-- set linkID to my randomize("0")
-- from original MMD scripts - commented out for use with Ulysses
-- set linkIDString to "[" & linkID & "]"
-- set tnString to "[Text Note]"
-- set linkIDString to ""
set tnString to "(Text Note)"
if noteType is "Underline" then
set noteString to noteString & "### " & formattedNote & " (" & correctedPage & ")" & LF & LF
else if noteType is "Text Note" then
set noteString to noteString & "#### " & formattedNote & " (" & correctedPage & ") " & tnString & LF & LF
else if noteType is "Highlight" then
set noteString to noteString & "> " & formattedNote & " (" & correctedPage & ") " & LF & LF
else
set noteString to noteString & "\"" & formattedNote & "\" (" & correctedPage & ") [" & noteType & "]" & LF & LF
end if
-- set refListText to refListText & "[" & linkID & "]: " & PDFLink & correctedPage & LF & LF
end if
end repeat
set finalText to theHeader & noteString & refListText
set the clipboard to finalText
end tell
display notification "Skim Notes copied to clipboard" with title "sk2c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment