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/c4fdf55ced9da54ebbf1418b6fabb8bb to your computer and use it in GitHub Desktop.
Save derickfay/c4fdf55ced9da54ebbf1418b6fabb8bb to your computer and use it in GitHub Desktop.
Export selected Skim notes to the clipboard using native Skim templates
(* EXPORT SELECTED NOTES TO THE CLIPBOARD
(no longer) requires hackademic URL handler from github user smargh
entirely rewritten to take advantage of Skim's built-in templating
2019-03-10 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 allNotes to notes of document 1
set activeNotes to note selection of document 1
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 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
end if
end repeat
set the clipboard to noteString
end tell
display notification "Skim Notes copied to clipboard" with title "skn"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment