Created
December 12, 2014 02:00
-
-
Save DrLulz/0a27de0c8a8edc9aea36 to your computer and use it in GitHub Desktop.
Idea taken from The Hackademic's Export Skim Notes to Evernote (http://hackademic.postach.io/export-all-skim-notes-directly-to-evernote). It requires the user to annotate pdf's in Skim using the designated favorite colors (http://www.alfredforum.com/topic/4052-skimmer-pdf-actions-for-skim/page-3#entry27286). After export it places a link in the …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" | |
if not (exists process "OmniOutliner") then | |
do shell script "open -a \"OmniOutliner\"" | |
end if | |
end tell | |
tell application "Skim" | |
set all_notes to every note of front document | |
set pdf_name to (name of front document) | |
set _file to (path of front document) | |
set file_url to my encode_text(_file, false, false) | |
set skimmer_url to "skimmer://" & file_url & "?page=" | |
--CHANGE THE NAME OF THE TEMPLATE TO ONE OF YOUR OWN | |
tell application id "com.omnigroup.OmniOutliner4" | |
set template to ((path to application support from user domain as string) & "The Omni Group:OmniOutliner:Templates:" & "Default.oo3template:") | |
open template | |
make new row with properties {topic:pdf_name} at end of rows of front document | |
tell application "System Events" to set frontmost of process "OmniOutliner" to true | |
end tell | |
repeat with i from 1 to count of all_notes | |
set _note to item i of all_notes | |
set _page to index of page of _note | |
set real_page to _page as string | |
set this_url to skimmer_url & _page | |
if type of _note is highlight note then | |
set note_text to text of _note | |
set rgba to color of _note | |
set {fav1, fav2, fav3, fav4, fav5, fav6} to favorite colors | |
tell application id "com.omnigroup.OmniOutliner4" | |
set doc to front document | |
set parentRow to my FetchLastRow(doc) | |
set parentLevel to level of parentRow | |
--set first_style to named style "Heading 1" of doc | |
--set second_style to named style "Heading 2" of doc | |
--set third_style to named style "Heading 3" of doc | |
--set red_highlight_style to named style "Highlight: Red" of doc | |
if rgba is fav1 then | |
set first_heading to make new row with properties {topic:note_text, note:this_url, state:checked} at end of rows of doc | |
--set style of first_heading to first_style | |
else if rgba is fav2 then | |
set second_heading to make new row with properties {topic:note_text, state:checked} at end of last child of doc | |
--set style of second_heading to second_style | |
else if rgba is fav3 then | |
repeat (parentLevel - 2) times | |
set parentRow to parent of parentRow | |
end repeat | |
set third_heading to make new row with properties {topic:note_text, state:checked} at end of parentRow | |
--set style of third_heading to third_style | |
else if rgba is fav4 then | |
if state of parentRow is checked then | |
try | |
make new row with properties {topic:note_text} at end of children of last row of last child of doc | |
on error | |
make new row with properties {topic:note_text} at end of children of last row of doc | |
end try | |
else | |
make new row with properties {topic:note_text} at end of parent of last row of doc | |
end if | |
else if rgba is fav5 then | |
if state of parentRow is checked then | |
try | |
make new row with properties {topic:note_text} at end of children of last row of last child of doc | |
on error | |
make new row with properties {topic:note_text} at end of children of last row of doc | |
end try | |
else | |
make new row with properties {topic:note_text} at end of parent of last row of doc | |
end if | |
else if rgba is fav6 then | |
if state of parentRow is checked then | |
try | |
set important_note to make new row with properties {topic:note_text} at end of children of last row of last child of doc | |
on error | |
set important_note to make new row with properties {topic:note_text} at end of children of last row of doc | |
end try | |
else | |
set important_note to make new row with properties {topic:note_text} at end of parent of last row of doc | |
end if | |
--set style of important_note to red_highlight_style | |
end if | |
end tell | |
end if | |
end repeat | |
tell application id "com.omnigroup.OmniOutliner4" to expandAll rows of front document | |
end tell | |
on FetchLastRow(doc) -- return the last row in an OmniOutliner document. If no rows, return the document itself. | |
tell application id "com.omnigroup.OmniOutliner4" | |
set doc to front document | |
if rows of doc is equal to {} then | |
return doc | |
end if | |
return last row of doc | |
end tell | |
end FetchLastRow | |
--URL encode text | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment