Skip to content

Instantly share code, notes, and snippets.

@DrLulz
Last active August 29, 2015 14:13
Show Gist options
  • Save DrLulz/55f17beebaf79e781edd to your computer and use it in GitHub Desktop.
Save DrLulz/55f17beebaf79e781edd to your computer and use it in GitHub Desktop.
Copies selected text, converts to titlecase, and then pastes into OmniOutliner as new row. Comment out line 16 to keep focus on document from which text originates. Change "txt_capped" to "txt" on line 18 to disable titlecase convert. Use Alfred or other manager to link script to hotkey.
tell application "System Events" to keystroke "c" using {command down}
-- if OO document is minimized unminimize
tell application id "com.omnigroup.OmniOutliner4"
if miniaturized of front window is true then
set miniaturized of front window to false
end if
end tell
-- send clipboard text to handler
set txt to the clipboard as text
set txt_capped to titlecase(txt)
-- identify current row, make new row from clipboard, then select the new row
tell front document of application id "com.omnigroup.OmniOutliner4"
activate --comment out to keep focus on copied text
set parent_row to «class OOpa» of last «class OOsr»
make new «class OOrw» with properties {«class OOtp»:txt_capped} at end of parent_row -- change "txt_capped" to "txt" to remove titlecase
«event OTREisal» «class OO+s» of last «class OOsr»
end tell
-- capitalize first letter of each word
on titlecase(txt)
return do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8')\" " & quoted form of txt
end titlecase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment