Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save fractaledmind/6418313 to your computer and use it in GitHub Desktop.

Select an option

Save fractaledmind/6418313 to your computer and use it in GitHub Desktop.
This script takes an outline from the clipboard and creates a set of Evernote notes that correspond to each item in the outline. For optimal usage, I recommend outlining in Numeral format (1, 1.1, 1.1.1, 2, 2.1, 2.1.1, 2.1.2, etc), as this ensures that the notes remain in order within the notebook when sorted by title.
--get input text
set theText to the clipboard
--get each line of outline as list
set theList to paragraphs of theText
--remove tabs and empty line feeds from list
set cleanList to {}
repeat with i from 1 to count of theList
set thisItem to item i of theList
if thisItem is not equal to "" then
set cleanItem to my trimBoth(thisItem)
copy cleanItem to end of cleanList
end if
end repeat
--ask user: create new outline notes in current or other notebook?
set theChoice to display dialog "Create new Outline Notes in selected notebook or choose other notebook?" with title "Outline to Evernote" buttons {"Use Selected", "Choose Other"} default button {"Use Selected"}
--create new notes
tell application "Evernote"
--create new "outline" tag if necessary
if (not (tag named "outline" exists)) then
set theTag to make tag with properties {name:"outline"}
else
set theTag to tag "outline"
end if
if theChoice = {button returned:"Use Selected"} then
set EN_sel to selection
if EN_sel is {} then display dialog "Please select a note."
repeat with i from 1 to count of EN_sel
set nb to name of notebook of item i of EN_sel
end repeat
repeat with i from 1 to count of cleanList
set thisItem to item i of cleanList
set newNote to create note title thisItem with text "" notebook nb
assign theTag to newNote
end repeat
else if theChoice = {button returned:"Choose Other"} then
set nbNames to name of every notebook
set nbNames to my simple_sort(nbNames)
set nbName to choose from list nbNames with title "Createnew Outline Notes in which Notebook?"
set nb to nbName as string
repeat with i from 1 to count of cleanList
set thisItem to item i of cleanList
set newNote to create note title thisItem with text "" notebook nb
assign theTag to newNote
end repeat
end if
end tell
(* HANDLERS *)
on trimBoth(str)
-- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
local str
try
return my trimStart(my trimEnd(str))
on error eMsg number eNum
error "Can't trimBoth: " & eMsg number eNum
end try
end trimBoth
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
(* SUB-ROUTINES *)
on trimEnd(str)
-- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
local str, whiteSpace
try
set str to str as string
set whiteSpace to {character id 10, return, space, tab}
try
repeat while str's last character is in whiteSpace
set str to str's text 1 thru -2
end repeat
return str
on error number -1728
return ""
end try
on error eMsg number eNum
error "Can't trimEnd: " & eMsg number eNum
end try
end trimEnd
on trimStart(str)
-- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
local str, whiteSpace
try
set str to str as string
set whiteSpace to {character id 10, return, space, tab}
try
repeat while str's first character is in whiteSpace
set str to str's text 2 thru -1
end repeat
return str
on error number -1728
return ""
end try
on error eMsg number eNum
error "Can't trimStart: " & eMsg number eNum
end try
end trimStart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment