Auto-filing from Outlook for Mac

Why would I go back to Outlook?

For number of reasons, I am unfortunately going back to using Outlook on my work machine. I was able to go with Mail and, for the past year, BusyCal. It was great except for Exchange. Turns out that Exchange is pretty vital to the whole experience of Email and Calendar in my work-life. Exchange has problems all on its own. There are issues at work between even the different versions of office on PC's. Macs bring more issues. BusyCal isn't the issue. If I could still use BusyCal, I'd probably not make the switch. I lost access to BusyCal as it seems to have fallen off the corproate whitelist for access to Exchange. So much of my issue is with Calendar. I've had multiple issues with calendar items simply not syncing with Exchange. The final straw was moving a meeting on Calendar and having the series disappear! With any of my more important meetings and meetings with large distribution lists, I had been opening Outlook to manage these. So to answer my own questions, I have a lack of confidence in Calendar syncing properly and to manage an Exchange based connection.

Switching Back

I've been keeping the Outlook option open all along so it was simple to switch over except with 2 issues. First, I didn't have my auto-filing scripts set up for Outlook. Second, my archives from Mail won't import into outlook (after exporting in .mbox format). I won't deal with this at the moment.

I missed my auto filing scripts immediately and have adapted the script. I miss BusyCal daily and am reduced to hoping the next Office for Mac improves.

Script Update

Applescript support for Office for Mac is very good so this wasn't a problem beyond my lack of experience at scripting Outlook. Ultimately, this was solvable and the results are below. The script replaces my Mail script and does what I've described previously.

Dual Stream Filing Approach

I took the opportunity to set up a second script that auto tags and puts the document on the desktop (with Hazel). The reason for this is that I save too many files which does often complicate the process of me finding files quickly. So my approach is to have a "curated" pile of files that go through the desktop and then the balance of files in a separate pile that go through the inbox. I'm much more likely to be looking for the files that I've been working with on the desktop. With Tembo, I can target a search easily for either set of files.

The key to this is Hazel. The scripts simply save the files to two different nested folders based on the senders name. From here, Hazel tags them using dynamic tags and either puts them on the desktop if they are from one set of nested folders or my inbox for the others. Not the most elegant solution but since its really just a bunch of empty folders most of the time, its not an issue.

The Script

also can be found my github repository.

-- set up the attachment folder path
tell application "Finder"
    set folderName to "Attachments"
    set homePath to (path to home folder as text) as text
    set attachmentsFolder to (homePath & folderName) as text
    -- display dialog attachmentsFolder
end tell

tell application "Microsoft Outlook"
    set theMessages to selection
    repeat with eachMessage in theMessages
        -- set the sub folder for the attachments to the first part of senders email before a period
        -- All future attachments from this sender will the be put here.
        set theSender to sender of eachMessage
        set theAddress to address of theSender
        -- display dialog theAddress
        set AppleScript's text item delimiters to "."
        set senderName to text item 1 in theAddress
        set subFolder to senderName
        -- display dialog senderName
        -- use the unix /bin/test command to test if the timeStamp folder  exists. if not then create it and any intermediate directories as required
        if (do shell script "/bin/test -e " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder) & " ; echo $?") is "1" then
            -- 1 is false
            -- display dialog attachmentsFolder & "/" & subFolder
            do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder)
        end if
            -- Save the attachment
            repeat with theAttachment in eachMessage's attachment
                set originalName to name of theAttachment
                set savePath to attachmentsFolder & ":" & subFolder & ":" & originalName
                    save theAttachment in file (savePath)
                end try
            end repeat
            --on error msg
            --display dialog msg
        end try
        -- set theArchiveMailboxName to "Processed"
        -- if (mail folder theArchiveMailboxName exists) = false then
        -- make new mail folder with properties {name:theArchiveMailboxName}
        --   end if
        -- repeat with aMessage in theMessages
        --  move aMessage to mail folder theArchiveMailboxName
        -- end repeat
    end repeat
end tell

In Search of a Better Filing System - Vision and Hints at a Breakthrough

So I’m thinking of how to be able to find folders more quickly in my reference system. Most of the files come in from email, are written by others, and I may need to pull them together in a summary document to present up to decision makers. In this context, what does productivity look like to me: it means I can find a document quickly. If I evaluate how things are going with my nested folders based on project name and a couple sub-folders, its a very mixed bag.

My vision is 2-fold:

  • I can find those files quickly to pull them out.
  • Once I pull any file out of any folder to the desktop or current working folder. I can have it automagically go back to where it should be filed.

This will be my current fiddly quest now that I have note-taking basically sorted out. I’ve made a bit of progress on both points just today.

I've been keeping track of how I've been finding and not finding files. Spotlight isn't really cutting it for a lot of cases. If I'm in a crunch, I usually go back to mail. Why? it is because I usually know who sent the file to me and about when they sent it. It turns out that often times, the contents of the file aren't enough for me to narrow the search down. Another problem I have is that I often have several versions of the documents in various stages of preparation (these are usually multiple drafts from multiple contributors) and outright duplicates in the system. This is a sub-problem that I’ll be going after later.

So what was the breakthrough? It involves a mail rule to automatically save attachments to a folder with the name of who sent it to me and Hazel to auto spotlight comment tag the file. Hazel also moves it to my “inbox” folder for further processing. This type of approach has been done before (insert here some of the stuff I found) but not in ways that worked for me (they weren’t simple enough for me). I'll have to extend the auto-tagging to my current nested folder structure and I should be there.

I’m going to have to clean up the script a bit and get some screen shots to illustrate it so that will be another post soon. In the meantime, I thought I would outline my current system in slightly more detail.

My go to setup for a while which has been infinitely better than the past is as follows:

4 main folders:

This set up comes from this post at Lifehacker

  • Now - these are currently active projects (think GTD projects here not my work project codenames).
  • Inbox - these are documents I have to figure out what to do with or need to get parsed into projects or filed.
  • Outbox - this is where stuff gets put to get filed or deleted. I have a large amount of Hazel rules mainly by subject title that move files to the right work based project folder in my last folder.
  • File Cabinet - Things get filed here by project with a couple of sub-folders.

I keep Now, Inbox, and Outbox synced to so that I have access to these files anywhere.

Update to Automatically Encrypting PDF with PDFPen via AppleScript and Hazel

I wasn't really happy with the security piece in the original simple script for encrypting PDFs and there isn't any scripting for keychain access anymore in Mountain Lion.  So I googled it and came up with a link that had a sample / demo script I could adapt at   To work, you need to store your selected password for your PDF's in the KeyChain (name in KeyChain should be inserted for PDFName and should be an application password.  It uses a built in 'security' command in OSX as explained by partron22 at  It will ask you for access to the KeyChain when the script executes and you can decide whether you want to grant access one-time or always.

The script (text at bottom) has has been set up to run in Hazel.  Hope this helps folks.

Script in Hazel

Script in Hazel

set this_file to theFile -- use this if you are using hazel 

set label to "PDFName" --this is the Name: in Keychain change for whatever you use
set Qlabel to quoted form of label
set t to do shell script "security 2>&1 find-generic-password -gl " & Qlabel
set text item delimiters to "\"" -- Get Password
set tlst to every text item of t
set pw to item 2 of tlst

tell application "PDFpen"
open this_file
save document 1 encrypt using AES256 password pw
end tell

An add to the Macsparky OmniFocus Hazel Rule

This post at Macsparky is great from a workflow standpoint to make sure the bill gets paid. I've tweaked to add the id of the file from Yojimbo so I can call up the bill.? You can spotlight search the id and get to the bill. I'm sure a link to the file could be set up this way but I don't have it yet.

The script adapted from post:?

set theDate to current date

set theTask to "Pay Bill"

tell application "Yojimbo"

set theLink to id of last pdf archive item of the library

end tell

set theNote to "Scanned or downloaded on " & (theDate as string) & " " & theLink

tell application "OmniFocus"

tell front document

set theContext to first flattened context where its name = "Home"

set theProject to first flattened project where its name = "Bills"

tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}

end tell

end tell