Created
January 25, 2015 07:10
-
-
Save DrLulz/b121e1642fee4b6e8fb9 to your computer and use it in GitHub Desktop.
Create XML from Evernote Notes
This file contains hidden or 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
on run argv | |
set query to argv as text | |
set final_list to {} | |
tell application id "com.evernote.Evernote" | |
set notebook_list to every notebook | |
set compiled_list to {} | |
repeat with book_ in notebook_list | |
set book_name to {its name} | |
set note_list to every note of book_ | |
repeat with note_ in note_list | |
set _title to title of note_ | |
set _uid to my get_uid(local id of note_, _title) | |
set end of compiled_list to my xmlItem({uid:_uid, arg:_title, |title|:_title, subtitle:"", valid:"yes", autocomplete:_title, icon:"en_book.png", iconAttribute:""}) | |
end repeat | |
end repeat | |
end tell | |
return giveFeedback(compiled_list as text) | |
end run | |
on get_uid(coredata, title) | |
set _cmd to "echo " & quoted form of coredata & quoted form of title & " | awk -F/ '{print $5}' | awk '{gsub(\" \",\"\",$0);print $0}'" | |
do shell script _cmd | |
end get_uid | |
on giveFeedback(xmlList) | |
set xmlHead to "<?xml version=\"1.0\"?>" & return & "<items>" & return | |
set xmlTail to "</items>" | |
return xmlHead & (xmlList as text) & xmlTail | |
end giveFeedback | |
on xmlItem(itemR) | |
set initial to {uid:"", arg:"", itemTypeAttribute:"file", valid:"yes", autocomplete:"", title:"", subtitle:"", icon:"", iconAttribute:""} | |
set itemR to itemR & initial | |
set myItem to tab & "<item uid=\"" & itemR's uid & "\" arg=\"" & itemR's arg & "\" type=\"" & itemR's itemTypeAttribute & "\" valid=\"" & itemR's valid & "\"" | |
if itemR's autocomplete ≠ "" then set myItem to myItem & " autocomplete=\"" & itemR's autocomplete & "\"" | |
set myItem to myItem & ">" & return | |
set myItem to myItem & tab & tab & "<title>" & itemR's title & "</title>" & return & tab & tab & "<subtitle>" & itemR's subtitle & "</subtitle>" & return | |
if itemR's iconAttribute ≠ "" then set itemR's iconAttribute to " type=\"" & itemR's iconAttribute & "\"" | |
if itemR's icon ≠ "" then set myItem to myItem & tab & tab & "<icon" & itemR's iconAttribute & ">" & itemR's icon & "</icon>" & return | |
set myItem to myItem & tab & "</item>" & return | |
return myItem as text | |
end xmlItem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment