Skip to content

Instantly share code, notes, and snippets.

@harrisony
Forked from DrLulz/skim-2-oo4.scpt
Created May 8, 2016 03:31
Show Gist options
  • Save harrisony/c8822071b260dfc9c1be02b15b939921 to your computer and use it in GitHub Desktop.
Save harrisony/c8822071b260dfc9c1be02b15b939921 to your computer and use it in GitHub Desktop.
Creates OmniOutliner document with hierarchy based on color of Skim highlights.
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_path to "file://localhost" & (path of front document)
tell application id "OOut"
tell application "Finder" to set dtb to bounds of window of desktop
make new document with properties {name:pdf_name}
make new row with properties {topic:pdf_name, note:file_path} at end of rows of front document
set status visible of front document to false
set doc to front document
set (bounds of windows where visible is true) to dtb
tell application "System Events" to set frontmost of process "OmniOutliner" to true
tell style of front document
set value of attribute "font-size" to 16
set value of attribute "font-family" to "Avenir Next"
--set value of attribute "font-family" to "M+ 1p"
set value of attribute "font-fill" to {21047, 21047, 21047, 65535}
set value of attribute "item-to-note-space(com.omnigroup.OmniOutliner)" to "4.0"
set value of attribute "item-child-indentation(com.omnigroup.OmniOutliner)" to "30.0"
--set value of attribute "shadow-color" to {57729, 57729, 57729, 65535}
--set value of attribute "shadow-offset" to "-1.0" --Why doesn't this work?
--set value of attribute "shadow-radius" to "1.2"
end tell
tell column title style of front document
set value of attribute "font-fill" to {57729, 57729, 57729, 65535}
set value of attribute "underline-style" to "none"
set value of attribute "font-weight" to 1.0
end tell
tell front document
set style_one to make new named style with properties {name:"Heading 1"}
set value of attribute "font-fill" of style_one to {16587, 28329, 55163, 65535}
set style_two to make new named style with properties {name:"Heading 2"}
set value of attribute "font-fill" of style_two to {39981, 38846, 25155, 65535}
set style_three to make new named style with properties {name:"Heading 3"}
set value of attribute "font-fill" of style_three to {23514, 43610, 18771, 65535}
set style_five to make new named style with properties {name:"Green Highlight"}
set value of attribute "text-background-color" of style_five to {59367, 61166, 56540, 65535}
set style_six to make new named style with properties {name:"Red Highlight"}
set value of attribute "text-background-color" of style_six to {63479, 59110, 58339, 65535}
end tell
end tell
(*************
--CHANGE THE NAME OF THE TEMPLATE TO ONE OF YOUR OWN ----> "GreyedOut Light.oo3template:"
tell application id "OOut"
set template to ((path to application support from user domain as string) & "The Omni Group:OmniOutliner:Templates:" & "GreyedOut Light.oo3template:")
open template
make new row with properties {topic:pdf_name, note:file_path} at end of rows of front document
tell application "System Events" to set frontmost of process "OmniOutliner" to true
--RENAME "Heading 1", "Heading 2", etc to MATCH STYLE NAMES OF YOUR TEMPLATE
set doc to front document
set style_one to named style "Heading 1" of doc
set style_two to named style "Heading 2" of doc
set style_three to named style "Heading 3" of doc
set style_five to named style "Highlight: Green" of doc
set style_six to named style "Highlight: Red" of doc
end tell
*************)
repeat with i from 1 to count of all_notes
set _note to item i of all_notes
set _page to "pg. " & index of page of _note
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 "OOut"
set row_last to last row of doc
if rgba is fav1 then
set head_one to make new row with properties {topic:note_text, note:_page} at end of rows of doc
add style_one to named styles of style of head_one
else if rgba is fav2 then
try
set head_two to make new row with properties {topic:note_text, note:_page} at end of last child of doc
on error
set head_two to make new row with properties {topic:note_text, note:_page} at end of rows of doc
end try
add style_two to named styles of style of head_two
else if rgba is fav3 then
global head_three
if "Heading" is in (name of named styles of style of row_last as string) then
set head_three to make new row with properties {topic:note_text} at end of last row's children of doc
else if level of parent of last row of doc ≤ 2 then
set head_three to make new row with properties {topic:note_text} at end of rows of parent of row_last
else
set head_three to make new row with properties {topic:note_text} at end of parent of last row's parent of doc
end if
add style_three to named styles of style of head_three
else if rgba is fav4 then
if "Heading" is in (name of named styles of style of row_last as string) then
make new row with properties {topic:note_text} at end of last row's children of doc
else if level of row_last > 1 and has subtopics of preceding sibling of row_last contains {} or {false} then
make new row with properties {topic:note_text} at end of parent of row_last
else
make new row with properties {topic:note_text} at end of last child of doc
end if
else if rgba is fav5 then
global head_five
if "Heading" is in (name of named styles of style of row_last as string) then
set head_five to make new row with properties {topic:note_text} at end of last row's children of doc
else if level of row_last > 1 and has subtopics of preceding sibling of row_last contains {} or {false} then
set head_five to make new row with properties {topic:note_text} at end of parent of row_last
else
set head_five to make new row with properties {topic:note_text} at end of last child of doc
end if
add style_five to named styles of style of head_five
else if rgba is fav6 then
global head_six
if "Heading" is in (name of named styles of style of row_last as string) then
set head_six to make new row with properties {topic:note_text} at end of last row's children of doc
else if level of row_last > 1 and has subtopics of preceding sibling of row_last contains {} or {false} then
set head_six to make new row with properties {topic:note_text} at end of parent of row_last
else
set head_six to make new row with properties {topic:note_text} at end of last child of doc
end if
add style_six to named styles of style of head_six
end if
end tell
end repeat
tell application id "OOut" to expandAll rows of front document
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment