14
Oct
NetNewsWire to Evernote — The Batch Send Applescript
Tags: API, Apple, Applescript, Evernote, NetNewsWire, tutorial
Change Log:
- 1.10 (October 13, 2009) **EXPORT URL LIST, BUG FIXES, UPDATED TAGGING, REMOVED EXTRA CONFIRMATIONS
- 1.01 (October 27, 2008) ADDED SOURCE URL TO NOTES
- 1.00 (October 14, 2008) INITIAL RELEASE OF SCRIPT
AppleScript ninjas — dive in to the code and, if you have any suggestions, leave them in the comment thread below.
And remember:
- These scripts are being provided for the benefit of the Mac community. While they work wonderfully for me, I cannot take responsibility for any data you might lose (or if your laptop turns into a pumpkin or something…);
- “Community” means “participation”. Please share with us *how* you use these scripts in your workflow, how you think they could be improved, and feel free to help your fellow ninjas if they don’t understand something!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | (* http://veritrope.com Batch Send -- NNW to Evernote Version 1.1 October 13th, 2009 Project Status, Latest Updates, and Comments Collected at: http://veritrope.com/tips/netnewswire-to-evernote-batch-send-applescript This script is primarily an adaptation of Daniel N. Byler's excellent DEVONthink script. http://bylr.net/3/2008/06/archive-newsfeeds-in-devonthink-pro-via-netnewswire/ Installation: Just drop it into the NetNewsWire Script Folder! FastScripts Installation (Optional, but recommended): --Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html --Copy script or an Alias to ~/Library/Scripts/Applications/NetNewsWire --Set up your keyboard shortcut CHANGELOG: 1.10 EXPORT URL LIST, BUG FIXES, UPDATED TAGGING, REMOVED EXTRA CONFIRMATIONS 1.01 ADDED "SOURCE URL" FUNCTIONALITY 1.00 INITIAL RELEASE *) property showAlert : true --if true, will display success/failure alerts property maxPause : 1 property criteriaList : {"All Items in Folder", "Flagged Items Folder", "Unread Items in Folder", "URLs of Tabs"} property successCount : 0 property selectCriterion : "" property every_headline : "" property every_URL : "" property abortScript : false property useGrowl : "" property growlAppName : "NetNewsWire to Evernote" property allNotifications : {"General", "Error"} property enabledNotifications : {"General", "Error"} property iconApplication : "Evernote.app" property NNWTag : "" property NNWTitle : "URL LIST" property NNWURL : "" property NNWBody : "" property NNWTabs : {} property EVnotebook : "" property postaction : "" -- CHECK FOR GROWL tell application "System Events" set processnames to name of every process end tell if "GrowlHelperApp" is in processnames then set useGrowl to true tell application "GrowlHelperApp" register as application growlAppName all notifications allNotifications ¬ default notifications enabledNotifications icon of application iconApplication end tell end if (*MAIN PROGRAM *) my main() on main() set oldDelims to AppleScript's text item delimiters tell application "NetNewsWire" activate my chooseArchiveCriterion() if selectCriterion is "false" then return end if my selectMatchingArticles(selectCriterion) set the_count to (count of every_headline) + (count of every_URL) if the_count is 0 then set abortScript to true display dialog "No valid content selected." with title "NetNewsWire to Evernote" buttons {"OK"} default button 1 ¬ with icon path to resource "appIcon.icns" in bundle (path to application "NetNewsWire") return end if set postaction to my choosePostAction(selectCriterion) if postaction is "false" then return end if activate (* DEACTIVATED WARNING -- DELETE COMMENT MARKERS TO REACTIVATE my warnArchiveTotal(every_headline) *) --"TAGGING AND BAGGING" SUBROUTINE my TagandBag(EVnotebook) activate if every_headline is not "" then my alertStart(every_headline, NNWTag, EVnotebook) repeat with i in every_headline my subArchiveMain(i, NNWTag, EVnotebook) my subPostAction(i, postaction) -- my pauseScript() end repeat else if every_URL is not "" then set i to every_URL my subArchiveMain(i, NNWTag, EVnotebook) set successCount to the_count end if activate my alertFinish(the_count, EVnotebook, successCount) set successCount to 0 end tell end main (* SUBROUTINES *) on chooseArchiveCriterion() tell application "NetNewsWire" activate set selectCriterion to ¬ (choose from list criteriaList default items "All" with title "NetNewsWire to Evernote" with prompt "Archive which items?") as string return end tell end chooseArchiveCriterion on selectMatchingArticles(selectCriterion) tell application "NetNewsWire" if selectCriterion is "All Items in Folder" then set every_headline to every headline of selectedSubscription else if selectCriterion is "Flagged Items Folder" then set every_headline to every headline of (first subscription whose display name is "Flagged Items") else if selectCriterion is "Unread Items in Folder" then set every_headline to every headline of selectedSubscription whose isRead is false else if selectCriterion is "URLs of Tabs" then set every_URL to URLs of tabs end if if every_headline is not "" then return every_headline else return every_URL end if end tell end selectMatchingArticles on choosePostAction(selectCriterion) tell application "NetNewsWire" if selectCriterion is "All Items in Folder" then set postaction to (choose from list {"Unflag", "Mark read", "None"} ¬ default items "None" with title "NetNewsWire to Evernote" with prompt "Post-Archive Action?") as string else if selectCriterion is "Flagged Items Folder" then set postaction to (choose from list {"Unflag", "None"} ¬ default items "None" with title "NetNewsWire to Evernote" with prompt "Post-Archive Action?") as string else if selectCriterion is "Unread Items in Folder" then set postaction to (choose from list {"Mark read", "None"} ¬ default items "None" with title "NetNewsWire to Evernote" with prompt "Post-Archive Action?") as string end if end tell return postaction end choosePostAction on subArchiveMain(i, NNWTag, EVnotebook) tell application "NetNewsWire" try -- HACK FOR MISSING BODY TEXT IN SOME ITEMS! set NNWTitle to title of i set NNWURL to URL of i if (description of i) exists then set NNWBody to (description of i) else set NNWBody to (summary of i) end if end try -- CREATE THE NOTE FROM HEADLINE tell application "Evernote" try if EVnotebook is "" and NNWTitle is not "URL LIST" then set n to create note with html NNWBody title NNWTitle tags NNWTag set source URL of n to NNWURL set successCount to successCount + 1 else if EVnotebook is not "" and NNWTitle is not "URL LIST" then set n to create note with html NNWBody title NNWTitle notebook EVnotebook tags NNWTag set source URL of n to NNWURL set successCount to successCount + 1 else tell application "NetNewsWire" set export_folder to POSIX path of (path to desktop folder as text) set t to export_folder & "tabs.html" export tabs as HTML to file t set NNWBody to POSIX path of t set NNWTitle to "Exported Tabs From NetNewsWire" tell application "Evernote" set n to create note from file NNWBody title NNWTitle tags NNWTag end tell tell application "Finder" to delete file t end tell --NNW end if end try end tell --EV end tell --NNW end subArchiveMain on subPostAction(i, postaction) tell application "NetNewsWire" if postaction is "Unflag" then set isFlagged of i to false else if postaction is "Mark read" then set isRead of i to true end if end tell end subPostAction on pauseScript() set rn to (random number (maxPause)) as text delay rn end pauseScript --"TAGGING AND BAGGING" SUBROUTINE on TagandBag(EVnotebook) tell application "NetNewsWire" set defaultTag to (display name of selectedSubscription) --DEFAULT TAG IS SELECTED SUBSCRIPTION NAME/FOLDER display dialog "" & ¬ "Enter Your Tags Below:" & return & return & " • Multiple Tags Separated By Colons or Commas" & return & return & " • Default Tag is The Highlighted Subscription Folder." with title "NetNewsWire to Evernote" default answer defaultTag buttons {"Send to Default Notebook", "Select or Create Notebook", "Cancel"} default button "Send to Default Notebook" cancel button ¬ "Cancel" with icon path to resource "Evernote.icns" in bundle (path to application "Evernote") set dialogresult to the result set tagText to text returned of dialogresult set ButtonSel to button returned of dialogresult set theDelims to {":", ","} set NNWTag to my Tag_List(tagText, theDelims) if ButtonSel is "Select or Create Notebook" then set EVnotebook to my Notebook_List() end tell end TagandBag --TAG SELECTION SUBROUTINE on Tag_List(userInput, theDelims) set oldDelims to AppleScript's text item delimiters set theList to {userInput} repeat with aDelim in theDelims set AppleScript's text item delimiters to aDelim set newList to {} repeat with anItem in theList set newList to newList & text items of anItem end repeat set theList to newList end repeat return theList set AppleScript's text item delimiters to oldDelims end Tag_List --EVERNOTE NOTEBOOK SELECTION SUBROUTINE on Notebook_List() tell application "Evernote" activate (*GET THE NOTEBOOK LIST *) set listOfNotebooks to {} set EVNotebooks to every notebook repeat with currentNotebook in EVNotebooks set currentNotebookName to (the name of currentNotebook) copy currentNotebookName to the end of listOfNotebooks end repeat (*SORT THE LIST *) set Folders_sorted to my simple_sort(listOfNotebooks) (*USER SELECTION FROM NOTEBOOK LIST *) set SelNotebook to choose from list of Folders_sorted with title "NetNewsWire to Evernote" with prompt ¬ "Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook" (*CREATE NEW NOTEBOOK OPTION *) if (SelNotebook is false) then set userInput to ¬ text returned of (display dialog "Enter New Notebook Name:" default answer "" with title "NetNewsWire to Evernote" with icon path to resource "Evernote.icns" in bundle (path to application "Evernote")) set EVnotebook to userInput else set EVnotebook to item 1 of SelNotebook end if end tell end Notebook_List --SORT SUBROUTINE 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 on warnArchiveTotal(every_headline) tell application "NetNewsWire" activate set result to display dialog "You're trying to archive " & return & (count of every_headline) & ¬ " articles. Continue?" buttons {"Cancel", "Continue"} giving up after 60 default button 2 with title "NetNewsWire to Evernote" with icon path to resource "appIcon.icns" in bundle (path to application "NetNewsWire") if button returned of result is equal to "Cancel" then set abortScript to true return end if end tell end warnArchiveTotal on alertStart(the_count, NNWTag, EVnotebook) activate if the_count is 0 then set alertName to "Error" set alertTitle to "Script failure" set alertText to "No valid content to archive" my notify(alertName, alertTitle, alertText) return (* DEACTIVATED ALERT -- DELETE COMMENT MARKERS TO REACTIVATE else activate set alertName to "General" set alertTitle to "Export to Evernote" set alertText to "Attempting to archive " & (count of every_headline) & " headlines into " & EVnotebook my notify(alertName, alertTitle, alertText) return *) end if end alertStart on alertFinish(the_count, EVnotebook, successCount) activate if successCount is 0 then set alertName to "Error" set alertTitle to "Script failure" set alertText to "Error: No Items Archived" my notify(alertName, alertTitle, alertText) return else set alertName to "General" set alertTitle to "Export to Evernote Successful!" set alertText to ¬ (successCount & " of " & the_count & " Items Archived!") as string my notify(alertName, alertTitle, alertText) return end if end alertFinish on notify(alertName, alertTitle, alertText) if showAlert is false then return else if useGrowl is true then tell application "GrowlHelperApp" notify with name alertName title alertTitle application name "NetNewsWire to Evernote" description alertText end tell else display dialog alertText with icon path to resource "appIcon.icns" in bundle (path to application "NetNewsWire") end if end notify |
Did this script help you out? Feel free to make a donation!
Interested in what other scripts are available for NetNewsWire and Evernote? Click here to see the latest list!
NetNewsWire to Evernote — The Batch Send ApplescriptPages: 1 2


13 Responses to “NetNewsWire to Evernote — The Batch Send Applescript”
Justin,
You beat me to it! And very glad you did – Evernote badly needed some extensibility. Also, I love the Growl detection – I may have to add that to my DEVONthink script.
All the best,
Dan
Thanks Dan!
Play around with it for a bit and let me know what you think — your input would be especially appreciated.
And be sure to try the FastScripts shortcuts…makes things a little more fast and, dare I say it, fun!
Thanks .Really awesome .God bless ya
I keep getting an error Evernote got an error: Operation would exceed monthly upload allowance. But I signed up for premium, and evernote web and evernote mac desktop know now that I am premium and am nowhere near upload limit. Your script is a lifesaver, if I can only get it to work around this problem. Any ideas where to look?
Thanks,
Rob
Hi Rob,
Glad you’re enjoying the script!
Let’s try to eliminate a few things so we can find out what’s going on:
1.) Be sure to empty the trash in Evernote; I believe that it also counts against the monthly quota, so let’s eliminate it as a cause of the message.
2.) Try moving the NNW items into a Local (not Synchronized) notebook with the script and then moving the items into a synchronized folder. Does doing it this way also give you an error message?
Let me know what happens after you’ve tried these two things and we’ll take it from there.
Oops, I’m in the same boat: premium acct and same error msg. Emptying Evernote’s trash and moving NNW items into a Local notebook didn’t make any difference.
I’m using Evernote 1.4.9 and NNW 3.2
Any help would be appreciated.
And thanks for all your Evernote applescript work! You’re helping a ton of people, I’m sure.
Hi David,
I am just finishing up some revisions to the DEVONthink/Evernote scripts, but I will tackle this next!
Check back later this week for updates and, in the interim, let me know if you discover any other “common denominator” associated with this error.
Hi Justin,
I just tried the script two more times and had partial success. Both attempts got about half way through my 125 flagged items before getting “Error number: -1712 Message: Evernote got an error: AppleEvent timed out.”
I don’t have good ideas on why I didn’t get the “exceed allowance” error I had earlier. Hard to tell since I changed a number of things including quitting many open applications. I also disconnected from the internet for one attempt (and ended up with no images in the newly created notes).
Your “single” script has worked fine throughout, so I may end up using that instead of the “batch” one. Nice to have a fallback.
BTW, I may contact you later to ask about a script to change the creation year on a notebook’s worth of notes (long story).
Thanks again for all your efforts!
I am definitely going to spend some time on this script this week — it’s been a year since I posted it and I have learned a few things about AppleScript since then.
Also, thanks for your detective work… I think I *may* have identified the cause, but will test over the next few days to be sure.
If and when you (or anyone else) would like to talk about commissioning a custom script, just use the Contact page!
thanks Justin,
I tried, still stuck. An email when/if you have a new script would be mighty kind–thanks for looking at this.
Rob info@hypoxia.net
Great script! Make my life so much easier.
The only thing i need to NNW to sync with Starred items or get a script to export my InstaPaper stuff to Evernote!
Ether way would make memory clippings easier on the iphone!
Joe,
From the NNW Website:
“Flagged items should now be in sync with starred items (both directions). One limitation, however — in NetNewsWire it only shows flagged items if the item appears in a feed you’re subscribed to.”
Tried it out with my iPhone — works fine!
Great script! I’ve been trying to use it with my starred items in Google Reader to get them into evernote. It worked well for a little bit, but it seems that it’s taking google a while to update my starred items public feed so I guess I’ll have to do a little bit each day.
Trackbacks/Pingbacks