Tag Archives: mail

AppleScript Tinkering Pt 2

I’ve finished building an AppleScript for automatically creating a Suggested Reading blogpost from my Evernote bookmarks quicker than I thought.

Mostly because in my previous posting on this I, in an example of blogging as thinking out loud, had already created a list of steps I wanted to take. That made it easier to build the step by step solution in AppleScript and find online examples where needed.

Other key ingredients were the AppleScript Language Guide, the Evernote dictionary for AppleScript (which contains the objects from Evernote available to AppleScript), the Evernote query language (for retrieving material from Evernote), and the Postie plugin documentation (which I use to mail to WordPress).

In the end I spent most time on getting the syntax right of talking to the WordPress plugin Postie. By testing it multiple times I ultimately got the sequence of elements right.

The resulting script is on duty from now on. I automatically call the script every Monday afternoon. The result is automatically mailed to my WordPress installation which saves it as a posting with a publication date set for Tuesday afternoon. This allows me time to review or edit the posting if I want, but if I don’t WordPress will go ahead and post it.

There is still some room for improvement. First, I currently use Apple Mail to send the posting to WordPress. My default mail tool is Thunderbird, so I had to configure Mail for this, which I had rather not. Second, the tags from Evernote that I use in the title of the posting aren’t capitalised yet, which I would prefer. Good enough for now though.

I’ve posted the code to my GitHub account, where it is available under an open license. For my own reference I also posted it in the wiki pages of this blog.

The bookmarks to use as listed in Evernote..

…and the resulting posting scheduled in WordPress

AppleScript Evernote to WordPress

This is an AppleScript I wrote to automatically post weekly overviews of bookmarks I made in Evernote, as a Suggested Reading post on my WordPress blog.

set singletaglist to {}
set multitaglist to {}
set alltaglist to {}
set allbulletlist to {}

--get the notes from Evernote
tell application "Evernote"
set query_string to "notebook:\"linklog\" created:day-7" --get notes since last week
set notities to find notes query_string --gives you list of relevant notes
set notenum to count of notities
repeat with notitie in notities
--for every note fetch title, tags and source
set titel to title of notitie
set bron to source URL of notitie
set taglist to tags of notitie
set numtags to number of items in taglist
--the taglist needs to be processed
repeat with counter from 1 to numtags
set tagtest to name of item counter of taglist
--if tag already encountered it goes to multitaglist
if (number of items in alltaglist is 0) then
copy tagtest to end of alltaglist
if (alltaglist contains tagtest) then
copy tagtest to end of multitaglist
--if not encountered it goes to all tags
copy tagtest to end of alltaglist
end if
end if
end repeat
--fetch content and cut down to first line
set inhoud to ENML content of notitie --gets you en xml, we want text between and

set AppleScript's text item delimiters to "" --text to the right of
set tinhoud to text item 2 of sinhoud
set AppleScript's text item delimiters to ""
set inhoud to ""
set sinhoud to ""
set thisbullet to {titel, bron, tinhoud} --list of this particual ever note
set end of allbulletlist to thisbullet
end repeat
end tell
-- we got what we need from Evernote
-- we now have a list of all items, but need to look at tags to create the title of post
-- I want a title like Suggested reading: tag1, tag2, tag3 and more
-- where two tags are used more than once and one just once
-- alltaglist contains all tags used, multitaglist contains all tags occurring multiple times
-- now create a list of tags that are used once (basically alltags minus multitags)
set allnum to number of items in alltaglist
set doubles to number of items in multitaglist
repeat with counter from 1 to allnum
if (multitaglist does not contain item counter of alltaglist) then copy item counter of alltaglist to end of singletaglist
end repeat
set singles to number of items in singletaglist
--I need 3 tags for the title, two used more than once, and one single. Unless there's not enough.
set posttitle to "Suggested Reading: "
if (allnum < 4) then -- too few tags, use them all repeat with counter from 1 to allnum - 1 set posttitle to posttitle & item counter of alltaglist & ", " end repeat set posttitle to posttitle & item allnum of alltaglist & " and more" else -- at least four tags available set takedouble to 2 --default value if (doubles < 2) then --take from doubles what possible set takedouble to doubles --0 or 1 end if if (singles = 0) then -- take all from doubles set takedouble to 3 end if --in all other cases default value works -- with value of takedouble now build posttitle if (takedouble = 3) then -- take first & last, and in the middle from doubles set middlelist to round doubles / 2 rounding up set posttitle to posttitle & item 1 of multitaglist & ", " & item middlelist of multitaglist & ", " & item doubles of multitaglist & " and more" end if if (takedouble = 2) then -- take first & last from doubles, first from singles set posttitle to posttitle & item 1 of multitaglist & ", " & item 1 of singletaglist & ", " & item doubles of multitaglist & " and more" end if if (takedouble = 1) then -- take first from doubles, first and last from singles set posttitle to posttitle & item 1 of multitaglist & ", " & item 1 of singletaglist & ", " & item singles of singletaglist & " and more" end if if (takedouble = 0) then -- take first middle & last,from singles set middlelist to round singles / 2 rounding up set posttitle to posttitle & item 1 of singletaglist & ", " & item middlelist of singletaglist & ", " & item singles of singletaglist & " and more" end if end if -- we now can start building the blog posting -- title is available posttitle -- now let's build the html for the posting --first opening line and start of UL set blogpostext to "

Some links I thought worth reading the past few days

    --for each bullet in bulletlist a new LI
    --with the blurb, and the title as href to the link
    repeat with listitem in allbulletlist
    set thislisitem to "

  • " & item 3 of listitem & ": " & item 1 of listitem & "
  • "
    set blogpostext to blogpostext & thislisitem
    end repeat
    --end the ul started at the top
    set blogpostext to blogpostext & "

" --we got it all now
--mail it to wordpress cat linklog, tags all tags, title and body.
--the content of the mail is determined by the Postie plugin settings
--the plugin used in my WordPress
-- cat and title in subject, rest in body: delay to post must come first, then body, then tags after one empty line
set mailsubject to "standard//[Linklog] " & posttitle
set tagtext to ""
repeat with counter from 1 to allnum - 1
set tagtext to tagtext & item counter of alltaglist & ", "
end repeat
set tagtext to tagtext & item allnum of alltaglist
set mailbody to "delay: 1d
set mailbody to mailbody & ":start " & blogpostext & "

tags: " & tagtext --don't use :end delimiter

--now send it as email
tell application "Mail"
set myMessage to make new outgoing message with properties {sender:"your@mail.com", subject:mailsubject, content:mailbody}
tell myMessage
make new to recipient with properties {address:"yoursecret@blogmail.com"}
end tell
send myMessage
delay 5 --wait for the mail to be processed
quit --quit Mail as I don't use it for anything else
end tell

Re-arranging my email process

Last week I have made changes in the way I process email. Adapting it more towards ‘Getting Things Done’, which I had avoided doing for years, and making some changes in daily habits around it. Now that I made the change, I can’t quite understand what kept me from doing it, even though before I thought my needs would not be met with a new routine.

Resisting change
As I use Gmail and have the notion I really shouldn’t, I mentally postponed changing my routines until ‘after replacing Gmail’, assuming I would otherwise either increase the cost of leaving Gmail (by having routines more deeply connected to its functionalities), or I’d find a replacement that already contained a better flow by default, making designing change now a waste of time. I know, neither make much sense upon closer consideration. Likely the real reason I made the change now, is having come back from a long vacation, and not many obligations yet as most clients are still away themselves. That, and receiving an external trigger right at that moment.

The trigger
That trigger was getting a message from Martin Roell, that one of his colleagues, Rob van den Brand, is offering a free download of how to deal with email. I downloaded it ouf of curiosity to see if it contained anything new in terms of suggestions. At first glance it didn’t, it was the GTD style approach I already knew (using the 2 minute rule, sorting into piles to reply, read, do and other etc.). Then a few days later a follow-up arrived with a few behavioral tactics to help make the mechanism work. The first one was unsubscribe to a lot of stuff, which led me to review my automated filtering, which led to re-evaluating the original GTD method, which led to implementing it……

The old routine
Over the years I kept all my e-mail in my inbox, always. Piling, never filing (tagging I do). The original reason for that was that my first mobile e-mail app would not let me easily access and search archived mail, only what was in my inbox would be readily available. The first step of my mail process is usually on my mobile.

From the newly arrived mail, I would ‘star’ those I thought would need some sort of follow-up. Things that don’t interest me I would leave unread but not throw out. This would be my basic triage method. I also have various filtering rules that label incoming mail (apart from ‘starred’) according to what part of my professional activities they represent (my company, my fablab stuff etc.) Using Gmail’s multiple inbox feature, those stars and labels were presented on my laptop screen as separate lists next to the main inbox.

At some point during the day I would open my mail (Gmail’s web interface) on my laptop and:

  • mark all remaining unread mail as read
  • work through the starred items
  • look at/answer mail while working on a specific professional context (1 of the inboxes)

The problem with this was that a starred mail could still mean many things (migh be interesting, immediate action, little or lots of work, read, keep in mind etc.) I basically needed to reevaluate every single mail, every time I opened up the ‘starred’ list. Over time that list would grow with unprocessed items from the past, becoming a ineffective mental drag, except for the recently starred messages. Also some of the multiple inboxes had survived beyond their waned usefulness due to changing focus and activities, and I had difficulty putting them to new good use.

The new routine
My current mobile app (the place where I do my first mail triage) fully supports labeling messages and accessing archived mails. Functionality I wasn’t putting to good use. So that makes it possible to do more detailed and better triage on incoming mail. I now, following the GTD material I mentioned above:

  • use many more filtering rules to automatically process and label incoming mails, alerts, mailers etc.
  • have unsubscribed a wide range of mailers connected to long time ago interests
  • have moved some quarter million mail exchanges of the past years from the inbox to the archive
  • label the remaining few mails that still reach my inbox with 1_reply, 2_todo, 3_toread, 4_waiting and other assorted relevant labels (such as ‘bookkeeping’, ‘opendata’, ‘acquisition’ etc.) so they can be more easily found back when needed
  • create new filtering rules when a mail arrives that warrants a filter
  • empty the inbox by moving all labeled and remaining unlabeled mail into the archive

The original multiple inboxes I now show below new mail, in stead of to the right where I had them for the past years. The multiple inboxes now show the reply/todo/read/waiting labels. That looks like this:


Key take-aways and needs
Changing my mail process and method of triage turned out to be easy. It moved the decision what to do with an e-mail forward 1 step, and made it part of the triage. (Before I would only star a mail and then decide later). This makes my normal daily time slot for mail sufficient to actually deal with the contents of that mail.

Main ‘win’ is that my mail interface is much less noisy, both due to heavier automated filtering and removing processed messages from the inbox. Before I would see whatever was left over from ‘before’ and always have a full page of messages in front of me. That clutter is now 5 short lists, with only one of those lists needing attention at any given time. All other stuff from mailing lists are available under a label/tag, when I decide I want to catch up but never clog up the inbox.

My main demand, being able to do triage ‘on the go’, is still being met (and more automated than before). The reduced clutter also feels like it might be a benefit when I move out of Gmail.

The only thing to still do is to much better connect the list of mails labeled to-do to my actual task management tool (Things, by Cultured Code) and making sure they get the right follow-up that way. I could probably automate that, but haven’t figured out how to do that yet. This may mean that the to-do part of the mail flow will actually disappear from my gmail altogether.