Outlook 2011 to OmniFocus

Description

Mac users who need fuller Exchange Server support often use Outlook 2011 (part of Microsoft's Office:mac 2011 package) as their primary email application. Here's an AppleScript for Outlook 2011 that lets you send items directly to (my favorite) task manger -- OmniFocus for Mac!

This script will send any type of Outlook item/items (messages, tasks, notes, calendar items, and contacts) directly to OmniFocus's Inbox -- and even will make a new task item from a highlighted bit of text. If there is existing due date information associated with the item, that should also make the jump as well. Using either 10.9's Notification Center or GROWL, you'll also receive status updates as Items are processed.

Yes… Attachments are included in the new OmniFocus item -- and you'll even get vCard and vCal attachments where appropriate!

IMPORTANT NOTES AND REQUIREMENTS

  • This AppleScript requires OmniFocus for Mac, OS X 10.9, and Outlook 2011 SP1 or Greater (Version 14.1.0+)
  • If you prefer to use GROWL notifications instead of Notification Center, set the following property in the USER SWITCHES section: property growlSwitch : "ON"

Installation Recommendations

  • Save this script to ~/Library/Application Support/Microsoft/Office/Outlook Script Menu Items (Or Its Equivalent in Localized Language). You can navigate quickly to this folder by selecting: Outlook's Script Menu => About This Menu... => Open Folder).
  • Give it a filename that enables a keyboard shortcut to be used.
  • Example: "Send to OmniFocusmO.scpt" lets you press ⌘O to send items to OmniFocus!

  • Enjoy!

The Code

(*
Veritrope.com
Outlook 2011 to Omnifocus
VERSION 1.12
October 12, 2017

// SCRIPT INFORMATION AND UPDATE PAGE
http://veritrope.com/code/outlook-2011-to-omnifocus

// REQUIREMENTS
THIS SCRIPT REQUIRES OS X 10.9+ AND OUTLOOK 2011 SP1 OR GREATER!
More details on the script information page.

// CHANGELOG
1.12  UPDATED PROPERTIES CODE
1.11  ADDED SWITCH TO DISABLE ATTACHMENTS, CHANGE FROM APPLICATION NAME TO BUNDLE ID TO AVOID VIRTUAL MACHINE CONFLICTS WITH OUTLOOK
1.10  FIX FOR OMNIFOCUS 2.0, GROWL/NOTIFICATION CENTER SWITCH, STARTING TO INTEGRATE NOTIFICATION CENTER
1.01  ADDED ORGANIZER INFO FOR MEETINGS
1.00  FINAL (UPDATED GROWL CODE)
1.00  BETA 1 - ASSORTED BUG FIXES
0.99  REVISED GROWL CODE
0.98  INITIAL RELEASE

// RECOMMENDED INSTALLATION INSTRUCTIONS:
1.) Save this script to ~/Documents/Microsoft User Data/Outlook Script Menu Items (Or Its Equivalent in Localized Language);
(You can navigate quickly to this folder by selecting:
 Outlook's Script Menu => About This Menu... => Open Folder)

2.) Give it a filename that enables a keyboard shortcut to be used.
   
Example:
Saving the script with the name "Send to OmniFocus\mO.scpt" lets you press ⌘O to send items to Evernote!

3.) Enjoy!

// TERMS OF USE:
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

*)


(*
======================================
// USER SWITCHES (YOU CAN CHANGE THESE!)
======================================
*)


--SET THIS TO "ON" IF YOU PREFER GROWL NOTIFICATIONS
--TO OSX'S NOTIFICATION CENTER (DEFAULT IS "OFF")
property growlSwitch : "OFF"

--SET THIS TO "OFF" IF YOU PREFER TO DISABLE
--ATTACHMENT PROCESSING (DEFAULT IS "ON")
property attachSwitch : "ON"


(*
======================================
// OTHER PROPERTIES (USE CAUTION WHEN CHANGING)
======================================
*)

property successCount : 0
property growl_Running : "false"
property myTitle : "Item"
property theAttachments : ""
property thisMessage : ""
property itemNum : "0"
property attNum : "0"
property errNum : "0"
property errorText : ""
property the_class : ""
property list_Props : {}
property SaveLoc : ""
property NewTask : {}

(*
======================================
// MAIN PROGRAM
======================================
*)


--LET'S GO!
try
    --CHECK FOR GROWL SWITCH
    if growlSwitch is "ON" then my startGrowl()
   
    --SET UP ACTIVITIES
    set selectedItems to {}
   
    set selectedItems to my item_Check()
   
    --MESSAGES SELECTED?
    if selectedItems is not missing value then
       
        --GET FILE COUNT
        my item_Count(selectedItems, the_class)
       
        --ANNOUNCE THE EXPORT OF ITEMS
        my process_Items(itemNum, attNum, the_class)
       
        --PROCESS ITEMS FOR EXPORT
        my item_Process(selectedItems)
       
        --DELETE TEMP FOLDER IF IT EXISTS
        set success to my trashfolder(SaveLoc)
       
        --NO ITEMS SELECTED
    else
        set successCount to -1
    end if
   
   
    --GROWL RESULTS
    if growlSwitch is "ON" then
        my growl_Growler(successCount, itemNum)
    else
        my notification_Center(successCount, itemNum)
    end if
   
    -- ERROR HANDLING
on error errText number errNum
    tell application "System Events"
        set isGrlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
    end tell
   
    ignoring application responses
        if isGrlRunning then
            if errNum is -128 then
                set part_1 to "tell application "Growl"
                "

                set part_2 to "notify with name ¬
                    "
Failure Notification" title ¬
                    "
User Cancelled" description "User Cancelled" application name ¬
                    "
Outlook to OmniFocus"
                    end tell"

            else
                -- GROWL FAILURE FOR ERROR
                set part_2 to "notify with name ¬
                    "
Failure Notification" title ¬
                    "
Import Failure" description "Failed to export due to the following error: " & return & errText ¬
                    application name "
Outlook to OmniFocus"
            end tell"

            end if
           
            -- NON-GROWL ERROR MSG. FOR ERROR
            display dialog "Item Failed to Import: " & errNum & return & errText with icon 0
        end if
    end ignoring
end try

(*
======================================
// PREPARATORY SUBROUTINES
======================================
*)


--APP DETECT
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning

--SET UP ACTIVITIES
on item_Check()
    tell application id "com.microsoft.Outlook"
        try -- GET MESSAGES
            set selectedItems to selection
            set raw_Class to (class of selectedItems)
            if raw_Class is list then
                set classList to {}
                repeat with selectedItem in selectedItems
                    copy class of selectedItem to end of classList
                end repeat
                if classList contains task then
                    set the_class to "Task"
                else
                    set raw_Class to (class of item 1 of selectedItems)
                end if
            end if
            if raw_Class is calendar event then set the_class to "Calendar"
            if raw_Class is note then set the_class to "Note"
            if raw_Class is task then set the_class to "Task"
            if raw_Class is contact then set the_class to "Contact"
            if raw_Class is incoming message then set the_class to "Message"
            if raw_Class is text then set the_class to "Text"
        end try
        return selectedItems
    end tell
end item_Check

--GET COUNT OF ITEMS AND ATTACHMENTS
on item_Count(selectedItems, the_class)
    tell application id "com.microsoft.Outlook"
        if the_class is not "Text" then
            set itemNum to [count of selectedItems]
            set attNum to 0
            try
                repeat with selectedMessage in selectedItems
                    set attNum to attNum + (count of attachment of selectedMessage)
                end repeat
            end try
        else
            set itemNum to 1
        end if
    end tell
end item_Count

(*
======================================
// PROCESS OUTLOOK ITEMS SUBROUTINE
======================================
*)


on item_Process(selectedItems)
    tell application id "com.microsoft.Outlook"
       
        --TEXT ITEM CLIP
        if (class of selectedItems) is text then
            set OFTitle to selectedItems
            set theContent to "Text Clipping from Outlook"
           
            --CREATE IN OMNIFOCUS
            tell application "OmniFocus"
                tell the first document
                    set NewTask to make new inbox task with properties {name:OFTitle, note:theContent}
                end tell
            end tell
           
            --ITEM HAS FINISHED -- COUNT IT AS A SUCCESS!
            set successCount to 1
        else
            --FULL ITEM EXPORT
            repeat with selectedItem in selectedItems
try
        set theProps to (properties of selectedItem)
on error
        set theProps to selectedItem
end try
                try
                    set theAttachments to attachments of selectedItem
                    set raw_Attendees to attendees of selectedItem
                end try
               
                --SET UP SOME VALUES
                set theCompletionDate to missing value
                set theStartDate to missing value
                set theDueDate to missing value
                set theFlag to false
               
                -- GET OUTLOOK ITEM INFORMATION
                set the_vCard to {}
               
                --WHAT KIND OF ITEM IS IT?
                if the_class is "Calendar" then
                   
                    (* // CALENDAR ITEM *)
                   
                    --PREPARE THE TEMPLATE 
                    --LEFT SIDE (FORM FIELDS)
                    set l_1 to "Event:  "
                    set l_2 to "Start Time:  "
                    set l_3 to "End Time:  "
                    set l_4 to "Location:  "
                    set l_5 to "Notes  :"
                   
                    --RIGHT SIDE (DATA FIELDS)
                    set r_1 to (subject of theProps)
                    set r_2 to (start time of theProps)
                    set r_3 to (end time of theProps)
                    set the_Location to (location of theProps)
                    if the_Location is missing value then set the_Location to "None"
                    set r_4 to the_Location
                   
                    --THE NOTES
                    set the_notes to ""
                    set item_Created to (current date)
                    try
                        set the_notes to (plain text content of theProps)
                    end try
                    if the_notes is missing value then set the_notes to ""
                   
                    --ADD ATTENDEE INFO IF IT'S A MEETING
                    if (count of raw_Attendees) > 0 then
                        set the_Organizer to "<strong>Organized By: </strong><br/>" & (organizer of selectedItem) & "<br/><br/>"
                        set the_Attendees to "Invited Attendees: " & return
                        repeat with raw_Attendee in raw_Attendees
                           
                            --GET ATTENDEE DATA
                            set raw_EmailAttendee to (email address of raw_Attendee)
                            set attend_Name to (name of raw_EmailAttendee) as text
                            set raw_Status to (status of raw_Attendee)
                           
                            --COERCE STATUS TO TEXT
                            if raw_Status contains not responded then
                                set attend_Status to "Not Responded"
                            else if raw_Status contains accepted then
                                set attend_Status to "Accepted"
                            else if raw_Status contains declined then
                                set attend_Status to "Declined"
                            else if raw_Status contains tentatively accepted then
                                set attend_Status to "Tentatively Accepted"
                            end if
                           
                            --COMPILE THE ATTENDEE DATA
                            set attend_String to attend_Name & " (" & attend_Status & ")" & return
                            set the_Attendees to the_Attendees & attend_String
                        end repeat
                        set the_notes to (the_Organizer & the_Attendees & the_notes)
                        set raw_Attendees to ""
                    end if
                   
                    --ASSEMBLE THE TEMPLATE
                    set theContent to l_1 & r_1 & return & l_2 & r_2 & return & l_3 & r_3 & return & l_4 & r_4 & return & return & return & return & the_notes & return & return
                   
                    --EXPORT VCARD DATA
                    try
                        set vcard_data to (icalendar data of theProps)
                        set vcard_extension to ".ics"
                        set the_vCard to my write_File(r_1, vcard_data, vcard_extension)
                    end try
                   
                    set OFTitle to r_1
                   
                    (* // NOTE ITEM *)
                else if the_class is "note" then
                   
                    --PREPARE THE TEMPLATE 
                    --LEFT SIDE (FORM FIELDS)
                    set l_1 to "Note:  "
                    set l_2 to "Creation Date:  "
                    set l_3 to "Category:  "
                    set l_4 to ""
                    set l_5 to "Notes:  "
                   
                    --RIGHT SIDE (DATA FIELDS)
                    set r_1 to name of theProps
                    set item_Created to creation date of theProps
                    set r_2 to (item_Created as text)
                   
                    --GET CATEGORY INFO
                    set the_Cats to (category of theProps)
                    set list_Cats to {}
                    set count_Cat to (count of the_Cats)
                    repeat with the_Cat in the_Cats
                        set cat_Name to (name of the_Cat as text)
                        copy cat_Name to the end of list_Cats
                        if count_Cat > 1 then
                            copy ", " to the end of list_Cats
                            set count_Cat to (count_Cat - 1)
                        else
                            set count_Cat to (count_Cat - 1)
                        end if
                    end repeat
                   
                    set r_3 to list_Cats
                    set r_4 to ""
                   
                    set item_Created to creation date of theProps
                   
                    --THE NOTES
                    try
                        set the_notes to plain text content of theProps
                    end try
                    if the_notes is missing value then set the_notes to ""
                   
                    --ASSEMBLE THE TEMPLATE
                    set theContent to l_1 & r_1 & return & l_2 & r_2 & return & l_3 & r_3 & return & l_4 & r_4 & return & return & return & return & the_notes & return & return
                   
                    --EXPORT VCARD DATA
                    set vcard_data to (icalendar data of theProps)
                    set vcard_extension to ".ics"
                    set the_vCard to my write_File(r_1, vcard_data, vcard_extension)
                   
                    set theHTML to true
                    set OFTitle to r_1
                   
                    (* // CONTACT ITEM *)
                else if the_class is "contact" then
                   
                    --PREPARE THE TEMPLATE 
                    --LEFT SIDE (FORM FIELDS)
                    set l_1 to "Name:  "
                    set l_2 to "Email:  "
                    set l_3 to "Phone Numbers:" & return
                    set l_4 to "Addresses:" & return
                    set l_5 to "Notes:"
                   
                    --GET EMAIL INFO
                    try
                        set list_Addresses to {}
                        set email_Items to (email addresses of theProps)
                        repeat with email_Item in email_Items
                            set the_Type to (type of email_Item as text)
                            set addr_Item to (address of email_Item) & " (" & my TITLECASE(the_Type) & ")" & return as text
                            copy addr_Item to the end of list_Addresses
                        end repeat
                    end try
                   
                    --GET PHONE INFO AND ENCODE TELEPHONE LINK
                    try
                        set list_Phone to {}
                        if business phone number of theProps is not missing value then
                            set b_Number to (business phone number of theProps)
                            set b_String to "-Work:  " & b_Number & return
                            copy b_String to end of list_Phone
                        end if
                        if home phone number of theProps is not missing value then
                            set h_Number to (home phone number of theProps)
                            set h_String to "-Home:  " & h_Number & return
                            copy h_String to end of list_Phone
                        end if
                        if mobile number of theProps is not missing value then
                            set m_Number to (mobile number of theProps)
                            set m_String to "-Mobile:  " & m_Number & return
                            copy m_String to end of list_Phone
                        end if
                    end try
                   
                    --GET ADDRESS INFO
                    try
                        set list_Addr to {}
                       
                        (*BUSINESS *)
                        if business street address of theProps is not missing value then
                            set b_Str to (business street address of theProps)
                            set b_gStr to my encodedURL(b_Str)
                            if (business city of theProps) is not missing value then
                                set b_Cit to (business city of theProps)
                                set b_gCit to my encodedURL(b_Cit)
                            else
                                set b_Cit to ""
                                set b_gCit to ""
                            end if
                            if (business state of theProps) is not missing value then
                                set b_Sta to (business state of theProps)
                                set b_gSta to my encodedURL(b_Sta)
                            else
                                set b_Sta to ""
                                set b_gSta to ""
                            end if
                            if (business zip of theProps) is not missing value then
                                set b_Zip to (business zip of theProps)
                                set b_gZip to my encodedURL(b_Zip)
                            else
                                set b_Zip to ""
                                set b_gZip to ""
                            end if
                            if (business country of theProps) is not missing value then
                                set b_Cou to (business country of theProps)
                                set b_gCou to my encodedURL(b_Cou)
                            else
                                set b_Cou to ""
                                set b_gCou to ""
                            end if
                            set b_Addr to b_Str & return & b_Cit & ", " & b_Sta & "  " & b_Zip & return & b_Cou
                           
                            --GOOGLE MAPS LOCATION IN URL
                            set b_gString to b_gStr & "," & b_gCit & "," & b_gSta & "," & b_gZip & "," & b_gCou
                            set b_GMAP to "http://maps.google.com/maps?q=" & b_gString
                            set b_String to "-Work: " & return & b_Addr & return & "(Link to Google Map:  " & b_GMAP & ")" & return
                            copy b_String to end of list_Addr
                        end if
                       
                        (*HOME *)
                        if home street address of theProps is not missing value then
                            set h_Str to (home street address of theProps)
                            set h_gStr to my encodedURL(h_Str)
                            if (home city of theProps) is not missing value then
                                set h_Cit to (home city of theProps)
                                set h_gCit to my encodedURL(h_Cit)
                            else
                                set h_Cit to ""
                                set h_gCit to ""
                            end if
                            if (home state of theProps) is not missing value then
                                set h_Sta to (home state of theProps)
                                set h_gSta to my encodedURL(h_Sta)
                            else
                                set h_Sta to ""
                                set h_gSta to ""
                            end if
                            if (home zip of theProps) is not missing value then
                                set h_Zip to (home zip of theProps)
                                set h_gZip to my encodedURL(h_Zip)
                            else
                                set h_Zip to ""
                                set h_gZip to ""
                            end if
                            if (home country of theProps) is not missing value then
                                set h_Cou to (home country of theProps)
                                set h_gCou to my encodedURL(h_Cou)
                            else
                                set h_Cou to ""
                                set h_gCou to ""
                            end if
                            set h_Addr to h_Str & return & h_Cit & ", " & h_Sta & "  " & h_Zip & return & h_Cou
                           
                            --GOOGLE MAPS LOCATION IN URL
                            set h_gString to h_gStr & "," & h_gCit & "," & h_gSta & "," & h_gZip & "," & h_gCou
                            set h_GMAP to "http://maps.google.com/maps?q=" & h_gString
                            set h_String to "-Home:  " & return & h_Addr & return & "(Link to Google Map:  " & h_GMAP & ")" & return
                            copy h_String to end of list_Addr
                        end if
                    end try
                   
                    --RIGHT SIDE (DATA FIELDS)
                    set r_1 to (display name of theProps)
                    set r_2 to (list_Addresses as string)
                    set r_3 to (list_Phone as text)
                    set r_4 to (list_Addr as text)
                   
                    --EXPORT VCARD DATA
                    set vcard_data to (vcard data of theProps)
                    set vcard_extension to ".vcf"
                    set item_Created to (current date)
                   
                    --THE NOTES
                    try
                        set the_notes to plain text note of theProps
                    end try
                    if the_notes is missing value then set the_notes to ""
                   
                    --ASSEMBLE THE TEMPLATE
                    set theContent to l_1 & r_1 & return & l_2 & r_2 & return & l_3 & r_3 & return & l_4 & r_4 & return & return & return & return & the_notes & return & return
                    set the_vCard to my write_File(r_1, vcard_data, vcard_extension)
                   
                    set OFTitle to r_1
                   
                    (* // TASK ITEM *)
                else if the_class is "Task" then
                   
                    --PREPARE THE TEMPLATE 
                    --LEFT SIDE (FORM FIELDS)
                    set l_1 to "Note:  "
                    set l_2 to "Priority:  "
                    set l_3 to "Due Date:  "
                    set l_4 to "Status:  "
                    set l_5 to "Notes:  "
                   
                    --RIGHT SIDE (DATA FIELDS)
                    set propClass to (class of theProps) as text
                    if propClass is "incoming message" then
                        set r_1 to (subject of theProps)
                    else
                        set r_1 to (name of theProps)
                    end if
                    set the_Priority to (priority of theProps)
                    if the_Priority is priority normal then set r_2 to "Normal"
                    if the_Priority is priority high then set r_2 to "High"
                    if the_Priority is priority low then set r_2 to "Low"
                   
                    set theDueDate to (due date of theProps)
                    set r_3 to theDueDate
                    set theCompletionDate to (completed date of theProps)
                    set theStartDate to (start date of theProps)
                    set item_Created to (current date)
                   
                    --TODO?
                    try
                        set todo_Flag to (todo flag of theProps) as text
                        set r_4 to my TITLECASE(todo_Flag)
                    end try
                   
                    --THE NOTES
                    try
                        set the_notes to plain text content of theProps
                    end try
                    if the_notes is missing value then set the_notes to ""
                   
                    --ASSEMBLE THE TEMPLATE
                    set theContent to l_1 & r_1 & return & l_2 & r_2 & return & l_3 & r_3 & return & l_4 & r_4 & return & return & return & return & the_notes & return & return
                   
                   
                    --EXPORT VCARD DATA
                    if propClass is not "incoming message" then
                        set vcard_extension to ".ics"
                        set vcard_data to (icalendar data of theProps)
                        set the_vCard to my write_File(r_1, vcard_data, vcard_extension)
                    end if
                   
                    set OFTitle to r_1
                   
                    (* // MESSAGE ITEM *)
                else
                   
                    --GET EMAIL INFO
                    set the_Sender to (sender of theProps)
                    set s_Name to (address of the_Sender)
                    set s_Address to (address of the_Sender)
                   
                    --REPLACE WITH NAME, IF AVAILABLE
                    try
                        set s_Name to (name of the_Sender)
                    end try
                   
                   
                    --GET CATEGORY INFO
                    set the_Cats to (category of theProps)
                    set list_Cats to {}
                    set count_Cat to (count of the_Cats)
                    repeat with the_Cat in the_Cats
                        set cat_Name to (name of the_Cat as text)
                        copy cat_Name to the end of list_Cats
                        if count_Cat > 1 then
                            copy ", " to the end of list_Cats
                            set count_Cat to (count_Cat - 1)
                        else
                            set count_Cat to (count_Cat - 1)
                        end if
                    end repeat
                   
                    --RIGHT SIDE (DATA FIELDS)
                    set m_Sub to (subject of theProps)
                    if m_Sub is missing value then
                        set r_2 to "<No Subject>"
                    else
                        set r_2 to {subject of theProps}
                    end if
                    set r_3 to (time sent of theProps)
                    set r_4 to list_Cats
                   
                    set theID to id of theProps as string
                    set item_Created to r_3
                    set OFTitle to r_2
                   
                    set theDueDate to (due date of theProps)
                    set theCompletionDate to (completed date of theProps)
                    set theStartDate to (start date of theProps)
                   
                    set oFlag to (todo flag of theProps) as text
                    if oFlag is "not completed" then
                        set theFlag to true
                    end if
                   
                    --PROCESS EMAIL CONTENT
                    set m_Content to plain text content of theProps
                    set theContent to "Name: " & s_Name & return & "Subject: " & r_2 & return & "Sent: " & r_3 & return & "Category: " & r_4 & return & return & return & return & m_Content & return & return
                end if
               
                --CREATE IN OMNIFOCUS
                tell application "OmniFocus"
                    tell the first document
                        set NewTask to make new inbox task with properties {name:OFTitle, note:theContent, flagged:theFlag, due date:theDueDate, completion date:theCompletionDate, defer date:theStartDate}
                    end tell
                end tell
               
                --ATTACH VCARD (IF PRESENT)
                if the_vCard is not {} then my vCard_Attach(the_vCard, theProps, NewTask)
               
                --IF ATTACHMENTS PRESENT, RUN ATTACHMENT SUBROUTINE
                if theAttachments is not {} then my message_Attach(theAttachments, theProps, NewTask)
               
                --ITEM HAS FINISHED! COUNT IT AS A SUCCESS AND RESET ATTACHMENTS!
                set successCount to successCount + 1
                set theAttachments to {}
            end repeat
        end if
    end tell
end item_Process

(*
======================================
// UTILITY SUBROUTINES
======================================
*)


--URL ENCODE
on encodedURL(the_Word)
    set scpt to "php -r 'echo urlencode("" & the_Word & "");'"
    return do shell script scpt
end encodedURL

--TITLECASE
on TITLECASE(txt)
    return do shell script "python -c "import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8')" " & quoted form of txt
end TITLECASE

--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

--REPLACE
on replaceString(theString, theOriginalString, theNewString)
    set theNum to 0
    set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString}
    set theStringParts to text items of theString
    if (count of theStringParts) is greater than 1 then
        set theString to text item 1 of theStringParts as string
        repeat with eachPart in items 2 thru -1 of theStringParts
            set theString to theString & theNewString & eachPart as string
            set theNum to theNum + 1
        end repeat
    end if
    set AppleScript's text item delimiters to od
    return theString
end replaceString


(*
======================================
// ATTACHMENT SUBROUTINES
=======================================
*)


--CLEAN TITLE FOR FILENAME
on clean_Title(rawFileName)
    set previousDelimiter to AppleScript's text item delimiters
    set potentialName to rawFileName
    set legalName to {}
    set illegalCharacters to {".", ",", "/", ":", "[", "]"}
    repeat with thisCharacter in the characters of potentialName
        set thisCharacter to thisCharacter as text
        if thisCharacter is not in illegalCharacters then
            set the end of legalName to thisCharacter
        else
            set the end of legalName to "_"
        end if
    end repeat
    return legalName
end clean_Title

--WRITE THE FILE
on write_File(r_1, vcard_data, vcard_extension)
    set ExportFolder to ((path to desktop folder) & "Temp Export From Outlook:") as string
    set SaveLoc to my f_exists(ExportFolder)
    set fileName to (my clean_Title(r_1) & vcard_extension)
    set theFileName to (ExportFolder & fileName)
    try
        open for access file theFileName with write permission
        write vcard_data to file theFileName as string
        close access file theFileName
        return theFileName
       
    on error errorMessage
        log errorMessage
        try
            close access file theFileName
        end try
    end try
end write_File

--FOLDER EXISTS
on f_exists(ExportFolder)
    try
        set myPath to (path to home folder)
        get ExportFolder as alias
        set SaveLoc to ExportFolder
    on error
        tell application "Finder" to make new folder with properties {name:"Temp Export From Outlook"}
    end try
end f_exists

--VCARD PROCESSING
on vCard_Attach(the_vCard, theProps, NewTask)
    tell application "OmniFocus"
        tell the note of NewTask
            make new file attachment with properties {file name:POSIX file the_vCard, embedded:true}
        end tell
    end tell
end vCard_Attach

--ATTACHMENT PROCESSING
on message_Attach(theAttachments, theProps, NewTask)
    if attachSwitch is "ON" then
        tell application id "com.microsoft.Outlook"
            --MAKE SURE TEXT ITEM DELIMITERS ARE DEFAULT
            set AppleScript's text item delimiters to ""
           
            --TEMP FILES PROCESSED ON THE DESKTOP
            set ExportFolder to ((path to desktop folder) & "Temp Export From Outlook:") as string
            set SaveLoc to my f_exists(ExportFolder)
           
            --PROCESS THE ATTCHMENTS
            set attCount to 0
            repeat with theAttachment in theAttachments
                set theFileName to (ExportFolder & theAttachment's name)
                try
                    save theAttachment in theFileName
                end try
                tell application "OmniFocus"
                    tell the note of NewTask
                        make new file attachment with properties {file name:file theFileName, embedded:true}
                    end tell
                end tell
               
                --SILENT DELETE OF TEMP FILE
                set trash_Folder to path to trash folder from user domain
                do shell script "mv " & quoted form of POSIX path of theFileName & space & quoted form of POSIX path of trash_Folder
            end repeat
        end tell
    end if
end message_Attach

--SILENT DELETE OF TEMP FOLDER (THANKS MARTIN MICHEL!)
on trashfolder(SaveLoc)
    try
        set trashfolderpath to ((path to trash) as Unicode text)
        set srcfolderinfo to info for (SaveLoc as alias)
        set srcfoldername to name of srcfolderinfo
        set SaveLoc to (SaveLoc as alias)
        set SaveLoc to (quoted form of POSIX path of SaveLoc)
        set counter to 0
        repeat
            if counter is equal to 0 then
                set destfolderpath to trashfolderpath & srcfoldername & ":"
            else
                set destfolderpath to trashfolderpath & srcfoldername & " " & counter & ":"
            end if
            try
                set destfolderalias to destfolderpath as alias
            on error
                exit repeat
            end try
            set counter to counter + 1
        end repeat
        set destfolderpath to quoted form of POSIX path of destfolderpath
        set command to "ditto " & SaveLoc & space & destfolderpath
        do shell script command
        -- this won't be executed if the ditto command errors
        set command to "rm -r " & SaveLoc
        do shell script command
        return true
    on error
        return false
    end try
end trashfolder

(*
======================================
// GROWL SUBROUTINES
======================================
*)

on startGrowl()
    try
        tell application "System Events"
            set isGrlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
        end tell
        ignoring application responses
            if isGrlRunning then
                set osaSc to "tell application "Growl"
set the allNotificationsList to {"
Import To OmniFocus", "Success Notification", "Failure Notification"}
set the enabledNotificationsList to {"
Import To OmniFocus", "Success Notification", "Failure Notification"}
register as application "
Outlook to OmniFocus" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "OmniFocus"
notify with name "
Import To OmniFocus" title "Import To OmniFocus Started" description "Processing Items from Outlook" application name "Outlook to OmniFocus"
end tell"

                set shSc to "osascript -e " & quoted form of osaSc & "  &>  /dev/null &"
                ignoring application responses
                    do shell script shSc
                end ignoring
            end if
        end ignoring
    end try
end startGrowl


--ANNOUNCE THE COUNT OF TOTAL ITEMS TO EXPORT
on process_Items(itemNum, attNum, the_class)
    try
        if growlSwitch is "ON" then
            tell application "System Events"
                set isGrlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
            end tell
           
            set app_Path to (path to application id "com.microsoft.Outlook")
           
            ignoring application responses
                if isGrlRunning then
                    set attPlural to "s"
                    set the_class to the_class as text
                    if the_class is "List" then set the_class to "Outlook"
                    if the_class is "Incoming Message" then
                        set growl_Icon to (path to resource "Mail.icns" in bundle app_Path)
                    else if the_class is "Contact" then
                        set growl_Icon to (path to resource "vCrd.icns" in bundle app_Path)
                    else
                        set growl_Icon to (path to resource "lcs.icns" in bundle app_Path)
                    end if
                    set growl_Icon to (POSIX path of growl_Icon) as text
                   
                    if attNum = 0 then
                        set attNum to "No"
                    else if attNum is 1 then
                        set attPlural to ""
                    end if
                   
                    tell application "Finder"
                        if the_class is not "Text" then
                            set Plural_Test to (itemNum) as number
                            if Plural_Test is greater than 1 then
                               
                                set osaSc to "tell application "Growl"
notify with name "
Import To OmniFocus" title "Import To OmniFocus Started" description "Now Importing " & itemNum & " " & the_class & " Items with " & attNum & ¬
                                    "
Attachment" & attPlural & "." application name ¬
                            "
Outlook to OmniFocus" identifier "OmniFocus" image from location "" & growl_Icon & ""
                            end tell"

                                set shSc to "osascript -e " & quoted form of osaSc & "  &>  /dev/null &"
                                my growlThis(shSc)
                            else
                                set osaSc to "tell application "Growl"
notify with name "
Import To OmniFocus" title "Import To OmniFocus Started" description "Now Importing " & itemNum & " " & the_class & " Items with " & attNum & ¬
                                    "
Attachment" & attPlural & "." application name ¬
                            "
Outlook to OmniFocus" identifier "OmniFocus" image from location "" & growl_Icon & ""
                            end tell"

                                set shSc to "osascript -e " & quoted form of osaSc & "  &>  /dev/null &"
                                my growlThis(shSc)
                            end if
                        end if
                    end tell --FINDER
                end if
            end ignoring
        end if
       
    end try
end process_Items

on growlThis(shSc)
    ignoring application responses
        do shell script shSc
    end ignoring
end growlThis

--GROWL RESULTS
on growl_Growler(successCount, itemNum)
    try
        tell application "System Events"
            set isGrlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
        end tell
       
        ignoring application responses
            if isGrlRunning then
                set part_1 to "tell application "Growl"
"

                set Plural_Test to (successCount) as number
                if Plural_Test is -1 then
                    set part_2 to "notify with name ¬
                    "
Failure Notification" title ¬
                    "
Import Failure" description "No Items Selected In Outlook!" application name ¬
                    "
Outlook to OmniFocus"
                    end tell"

                else if Plural_Test is 0 then
                    set part_2 to "notify with name ¬
                    "
Failure Notification" title ¬
                    "
Import Failure" description "No Items Exported From Outlook!" application name ¬
                    "
Outlook to OmniFocus"
                    end tell"

                else if Plural_Test is equal to 1 then
                    set part_2 to "notify with name ¬
                    "
Success Notification" title ¬
                    "
Import Success" description "Successfully Exported " & itemNum & ¬
                        "
Item to OmniFocus" application name ¬
                    "
Outlook to OmniFocus"
                    end tell"

                else if Plural_Test is greater than 1 then
                    set part_2 to "notify with name ¬
                    "
Success Notification" title ¬
                    "
Import Success" description "Successfully Exported " & itemNum & ¬
                        "
Items to OmniFocus" application name ¬
                    "
Outlook to OmniFocus"
                    end tell"

                end if
                set itemNum to "0"
                set combined_parts to part_1 & part_2
                set shSc to "osascript -e " & quoted form of combined_parts & "  &>  /dev/null &"
                my growlThis(shSc)
            end if
           
        end ignoring
    end try
end growl_Growler

--NOTIFICATION CENTER
on notification_Center(successCount, itemNum)
    set Plural_Test to (successCount) as number
   
    if Plural_Test is -1 then
        display notification "No Items Selected In Outlook!" with title "Outlook to OmniFocus" subtitle "Veritrope.com"
       
    else if Plural_Test is 0 then
        display notification "No Items Exported From Outlook!" with title "Outlook to OmniFocus" subtitle "Veritrope.com"
       
    else if Plural_Test is equal to 1 then
        display notification "Successfully Exported " & itemNum & ¬
            " Item to OmniFocus" with title "Outlook to OmniFocus" subtitle "Veritrope.com"
       
    else if Plural_Test is greater than 1 then
        display notification "Successfully Exported " & itemNum & ¬
            " Items to OmniFocus" with title "Outlook to OmniFocus" subtitle "Veritrope.com"
    end if
   
    set itemNum to "0"
    delay 1
end notification_Center

93 Responses to “Outlook 2011 to OmniFocus”

  1. Mac April 30, 2011 at 7:29 am #

    Just trying your script but I don’t have Growl installed. So it get stuck as it searches for GrowlHelper. Can it be deleted?

    • Justin Lancy April 30, 2011 at 11:55 am #

      Just made a small update to the code… is it working now?

      • Mac April 30, 2011 at 9:58 pm #

        Unfortunately not. When I tried to compile the script, it still asked for GrowlHelperApp in a pop up window.

        And then there was syntax error.
        Quote—
        Expected “given”, “into”, “with”, “without”, other parameter name, etc. but found “””.
        End Quote—
        This referenced the line: “Failure Notification” title ¬

        • Justin Lancy May 1, 2011 at 2:51 am #

          Mac,

          I just sent you an email with a revised script attached.

          Let me know if this fixes the Growl issue for you and, if so, I’ll update the code for everyone else!

          • Mac May 5, 2011 at 9:40 am #

            Growl issue fixed. Thanks.

  2. Shaun April 30, 2011 at 6:10 pm #

    Hi Justin,

    I am trying to install your script but when I open it with my script editor and then try and save it I keep getting the following errors about 7 – 8 times;

    Expected “,” but found property
    Expected expression but found “of”

    They both appear about 4 times each. When i go through and remove what i think are the culprits and then run the script again I get the Omnifocus notification that it has started trying to import something but then I get another error that says;

    Import failure
    Failed to export item due to the following error
    “The variable selecteditems is not defined”

    Can you help with this? Your script seems to be the best one in terms of what it offers as all the other ones I have found only send emails form Outlook and not Calendar items. I need the calendar items more than the emails to be honest.

    Cheers

    Shaun

    • Justin Lancy April 30, 2011 at 6:21 pm #

      Hi Shaun,

      That’s really odd! Haven’t seen/heard of that happening before…

      Let’s try to sort out what’s causing the issue:
      To me, it sounds like the script isn’t compiling correctly on your end. Instead of using the ‘Open in Script Editor” button, try cutting-and-pasting the code into your Script Editor and then compiling. Does that work?

      • Shaun April 30, 2011 at 6:27 pm #

        Wow that’s a quick reply. Thanks a lot.
        OK I tried copying and pasting directly into a new page in the script editor and then ran it and I get the same error. Exactly the same errors.

        • Justin Lancy April 30, 2011 at 6:36 pm #

          I do what I can… 😉

          Seriously, though — It’s really important to me to make sure that people can get these scripts up and running (especially in the early days of putting a beta out into the world).

          Probably better if we try to diagnose things one-on-one via email. I’ll send you a copy of the script (one that is compiling fine on my system) as an attachment. If it still isn’t working, we can drill down deeper to see what’s going on!

          Let me know via the Contact Form if you don’t receive it!

          • Shaun April 30, 2011 at 6:37 pm #

            Awesome! Sounds like a plan.

            Thanks

  3. Justin Lancy May 1, 2011 at 2:54 am #

    FYI — Shaun’s issue was caused by running an older version of Outlook 2011. This AppleScript requires SP1 (Version 14.1.0) or greater.

    I’ll update the script’s notes to reflect that in case this crops up again!

  4. Mark Duffield May 1, 2011 at 8:50 pm #

    Working great for me with Outlook and OmniFocus. Thank you! This is the missing link for me.

    • Justin Lancy May 2, 2011 at 3:30 am #

      Mark,

      I really appreciate you taking time to let me know that it’s working well — hope you enjoy it!

  5. Jan May 2, 2011 at 8:36 am #

    Justin,

    still a newbie in Applescript, so I am not able to say where the error is…

    if trying to save/compile the code, I receive multiple syntax errors:
    if raw_Class is calendar event then set the_class to “Calendar”

    if raw_Class is incoming message then set the_class to “Message”

    the two words seems to be problem, expecting Then

    and the second part:
    set r_2 to (start time of theProps) expected “,” but found property, same with end time, one line below…

    Please help, Jan

    • Justin Lancy May 2, 2011 at 12:20 pm #

      Hi Jan!

      That’s odd. Let’s get a little more detail — Are you cutting-and-pasting the code into the AppleScript Editor or did you use the “Quick Link” button that I have underneath the code? What version of OS X, Outlook, and Evernote do you have?

      • Jan May 2, 2011 at 4:00 pm #

        I tried both ways: cut & paste and opening in AppleScript Editor…

        all the latest versions:
        Evernote: 2.1.0
        Omnifocus: 1.9
        Outlook: 14.1.0 (110310)
        Mac OS X 10.6.7

        • Justin Lancy May 2, 2011 at 4:07 pm #

          I’ll email you a copy of the script that compiles properly on my machine (with all the same versions that you have!) and we’ll take things from there… sound good?

          • Jan May 2, 2011 at 4:10 pm #

            sounds good 🙂 Go for it, I am ready for some rock-and-roll 🙂

          • Justin Lancy May 2, 2011 at 4:12 pm #

            Sent!

          • Sameer November 12, 2011 at 9:25 pm #

            HI Justin,
            would love to use this script, but, am having the same issues as Jan.

            Were you able to figure out what the issue was?

            Look forward to using your script.

            regards,
            sameer

          • paul November 26, 2013 at 12:43 pm #

            where you able to get this resolved with the script that was emailed? I’m having the same exact problem.

  6. Mark Johnson May 2, 2011 at 12:53 pm #

    Justin,

    Thanks so much for this wonderful and promising script. It truly is the missing link for me! Now I can delete that Entourage-based script I was using for a while, which always worked but ended with some sort of error-message. What you have here is remarkably elegant.

    • Justin Lancy May 2, 2011 at 2:04 pm #

      “Elegant” is quite a nice compliment, Mark… Thank You! 😀

  7. Paul Bain May 2, 2011 at 6:20 pm #

    You may want to check out the coding that is being used in the AppleScript at http://rainer.4950.net/wordpress/blog/2011/02/15/outlook-to-omnifocus-take-4/

    What’s nice about this script is that it includes the message as an attachment which can be opened.

    • Justin Lancy May 2, 2011 at 6:43 pm #

      Hi Paul,

      I saw Rainer’s script and agree that, if you’re looking for the message as an attachment, it’s a pretty nice solution!
      (And also a good one if you prefer to use the Quick Entry Dialog)

      For my script, I decided to take a different approach: I wanted something that could transfer all Outlook items — not just the messages. Since I also present the scripts here as a way to help people learn AppleScript, I also wanted something that was self-contained and written in pure AppleScript (Rainer’s depends on an external Java file called “MailDecoder.jar” to get the job done).

      There are usually multiple ways to get to the same end result and I almost always learn from seeing how other people approach their own scripting projects. This is one of my favorite parts of AppleScript and why I wanted to have a code library… People should check out Rainer’s script at the link above and I’ll be sure to leave a link on Rainer’s site so that people know about this version as well!

  8. Nitin May 14, 2011 at 1:31 am #

    Is there a similar way to pass an outlook object over to Omni Outliner?

    Great script for OF, by the way.

    • Justin Lancy May 17, 2011 at 10:31 pm #

      I can’t say for certain because I haven’t written anything for OmniOutliner yet (though that may change now that I’m using the hell out of the iPad version of OmniOutliner. However given Omni’s generally deep support of AppleScript in their products, I think it would probably be achievable!

      Tell me — how would you imagine it working?

  9. Doug May 25, 2011 at 10:19 pm #

    Terrific script – thank you!

    I was wondering if there was a way to do:

    1. Define a rule that runs your script for autoprocessing of selected incoming emails? I’d like to automatically send selected emails to OF.

    2. Allow me to auto-set OF’s Context and Project fields. I have some of my Contexts set to the name of key people. When I receive an email, I’d like the Context to be auto-determined. My thought is that there would be a set of “If..then..else” statements in the script that would say, if the email from name contains “Bob.Smith”, then set the OF Context to “BSmith”. Same kinda idea with Projects.

    BTW – Tried to use your script for auto-processing and all I get in OF is a task with “Text Clipping from Outlook” as the note.

    Thanks again for putting this together – I really appreciate it!

    Doug

    • Justin Lancy May 25, 2011 at 10:38 pm #

      Hi Doug,

      I haven’t done this yet, but I think it’s possible!

      I’m guessing you’d need to modify the script in the following ways:

      1. Place the whole script inside an “on run” block (Here’s an example of that using Outlook’s predecessor, Entourage.)
      2. As you were thinking, some If/Then statements which set the Projects/Contexts. Here is some sample code that shows how to work with contexts and projects.

      If you successfully put together a “Rule Ready Version”, be sure to let us all know how it worked out for you… Good Luck!

      • Doug May 26, 2011 at 8:01 pm #

        Thanks, Justin! I appreciate the feedback, examples and encouragement. I’ll let you know how it turns out. Apple scripting is way outside my comfort zone, so no promises! Thanks again!

  10. Doug May 29, 2011 at 7:35 pm #

    Hey Justin – I’ve made the changes that support automatically determining start and due dates, contexts, and projects. I also added the ability to optionally load OF in the background or in the foreground (via quick entry). If you send me your email, I’ll send it to you.

    A few challenges I’d like to overcome:

    1. Is there a way for the script to know what the key commands were that initiated it? I’d like to be able to use the same script to optionally load the OF task in the background and foreground. At the moment, I have a switch at the top of the script and I create two scripts to do one or the other.

    2. I’d like to be able to use this script to run based on a rule on incoming emails. OF has one that they use for Mail, but I can’t get this process to work using this script. It basically uses the highlighted inbox message and not the email that initiated the rule.

    3. I tried to use sub routines, but I was not successful. So, the block of script that determines dates, contexts, projects, etc, is in two places to support background and then foreground processing.

    4. Lastly, your script does not attach attachments to the OF task. Growl says that it is doing it, but it does not. Is there a later version of the script?

    Thanks again for the coaching!

  11. Jay June 5, 2011 at 8:12 pm #

    Great script! I have been using another one I found on the internet, but this one is much faster and I love the growl notification. I have a request – can you have a link to the original email message posted into the notes section along with the text of the outlook message?

    This would be much appreciated!

    • Justin Lancy June 5, 2011 at 8:27 pm #

      I would love to do this but, as far as I know, Outlook currently lacks the ability to create Direct Links to its messages… but I’ll keep my eyes open and add it should that ever be enabled!

  12. Glenn June 13, 2011 at 10:39 am #

    Hi – would love to get this working – having the GrowlHelperApp window popping up. What should I do next? Use a modified script? Thx

    • Justin Lancy June 13, 2011 at 1:57 pm #

      Hi Glenn,

      Try the newly updated beta… Does this fix it for you?

  13. Doug June 13, 2011 at 2:23 pm #

    Justin – do you want me to send you the script I updated? As I mentioned, I’ve made a number of changes that may be generally helpful. Please send me your email if you’d like for me to send it to you.

    Doug

    • Justin Lancy June 13, 2011 at 2:35 pm #

      Hi Doug — Apologies! I must have missed your original comment somehow. 🙁

      Would love to see your mods! FYI — the best way to send compiled AppleScripts to me is via the AppleScript Submission Form. By doing so, it makes it easy for me to share it with everyone in the Code Library and give you proper attribution for your contributions.

      Looking forward to checking it out!

  14. Eric June 20, 2011 at 10:45 pm #

    Hi Justin,

    Does this require the latest version of OmniFocus? I am still using 1.7.5 and have not upgraded–it looks like I can export highlighted text but am unable to directly copy messages, etc.

    • Justin Lancy June 20, 2011 at 10:56 pm #

      That’s a good question, Eric!

      I built this script on OmniFocus 1.9 and I don’t have any other versions installed to test for compatibility. Anyone out there running this on an earlier revision?

  15. Adam August 23, 2011 at 10:08 am #

    Justin,
    This is a great tool. Much appreciated. I know nothing of writing code / managing scripts… I’m an executive who loves mac and omnifocus… I almost didn’t try this because it was way over my head… the perceived benefit was greater than the risks so I dove in… Being completely lost, I clicked on the quick link you provided to script editor, saved it to the location you specified, copied your file name and pasted it in… Works like a charm. Could be the best couple of minutes I invest all week! Thank you for making it easy!
    Adam

    • Justin Lancy August 24, 2011 at 7:50 am #

      Adam,

      Thanks so much for your kind note!

      You put your finger on something that I’ve been wondering about: Whether people come here, see the code, and feel intimidated or like it’s “over their head”.

      I’ve been working behind the scenes on the next version of Veritrope.com, trying to come up with a way to present things that is useful to new and experienced users alike. (Suggestions, as always, are welcomed by using the Contact Form or with a note to the Veritrope.com Twitter account)

      Anyhow, I’m certainly glad you decided to “take the plunge” and am very happy to read how well things are working out for you!

      • Adam September 22, 2011 at 11:10 pm #

        Justin,
        Thanks for the kind reply last month. Wanted to let you know that I recently had a microsoft update come through that wiped out the script (at least I think that is what did it). I went through the process of reinstalling it and it works well again… thank goodness… but just in case you get a flurry of these issues it was completely wiped from my script folder… I look forward to venturing out further into Veritrope to see what else I can learn/use.
        Thanks again for making it easy!

        Adam

  16. Doug August 27, 2011 at 4:36 pm #

    Justin,

    This is an outstanding tool. I like Adam am also an executive who knows nothing about code. I was able to get this up and running in five minutes. Being able to integrate my emails to Omni was the biggest reason I put off buying it for so long – as most folks – I live out of my inbox and nothing has the power of OF. Thank you again – very nice job!

    • Justin Lancy August 27, 2011 at 6:47 pm #

      Doug,

      I’m so glad to read that this script helped you as well!

      As I mentioned to Adam above, I’m working on ways to demystify tools like these to newer users and comments like yours reinforce the value of this.

      Thank you so much for taking time to share your experience!

  17. bob September 13, 2011 at 11:49 pm #

    great script (for me new to Mac and OF).
    i installed and it worked perfectly, then i changed default programs to Mac mail to test something else out, then when i changed back to Outlook 2011, the script no longer works… i tried removing and then reinstalling, still no luck… any ideas?

    • Justin Lancy September 14, 2011 at 2:39 am #

      Hi Bob — Glad that you like the script!

      Your issue is a bit of a head-scratcher… but let me send you an email to outline some basic troubleshooting steps to see if we can figure it out.

  18. Steven Perich September 19, 2011 at 3:35 am #

    Hi there,

    LOVE the script. Thank you for writing it. I really like how it can be used for other things apart from emails!

    I am running Outlook 2011 14.1.3 at present and I noticed that when I try to import a contact (by clicking it and invoking the script) I get an error:

    Item Failed to Import: -1278
    Microsoft Outlook got an error: Can’t get every attachment of item 1 of contact id 2.

    Any ideas?

    • Justin Lancy September 19, 2011 at 4:30 am #

      Thanks for your kind comment, Steven!

      I made a slight tweak to the code to see if it would avoid this error. Download the new version (I’m calling this 1.00 Beta 1) when you get a chance and let me know if it does the trick.

  19. Steve Nunez September 27, 2011 at 11:45 pm #

    Thanks for the script. Just what was looking for. One suggestion: a pop up entry windows, similar to how the Omnifocus (clip-o-tron) mail clipping services works would be great. This would let you clean up the task before saving it.

    Is this possible?

    • Justin Lancy September 29, 2011 at 12:29 pm #

      @Steve –I think it would be possible to integrate this into the script for single items. My original concept avoids the quick entry tree because I felt that, for multiple items, it would be faster to just get everything into the inbox.

      Veritrope readers — Would this be helpful to you? Any other thoughts or suggestions?

  20. Eldar October 26, 2011 at 12:26 pm #

    Working great for me with Outlook2011 and OmniFocus. Thank you!

  21. DanitaZ April 3, 2012 at 12:39 pm #

    This is working well for me, except that the growl notification is not popping up. I just have to learn to “trust” that the items are getting to OmniFocus. But otherwise it’s a gem!

    • Justin Lancy April 3, 2012 at 12:45 pm #

      Thanks for the donation, Danita! 😀

      Question about your GROWL issue: Do you have the newer, “app store” version installed or the older version?

      • DanitaZ April 3, 2012 at 1:14 pm #

        Oh good point! I’m pretty sure it’s the older version. I keep getting “nagged” to upgrade, but it was “working” for everything else, and I’m an “it’s not broke, don’t fix it” type generally. I can go put the newer version on and see if that helps!

  22. John May 16, 2012 at 6:16 am #

    Many many thanks for this, works very well (once I had selected the right bits), really appreciate your hard work in writing and sharing this.

  23. Dennis June 7, 2012 at 9:29 am #

    Thanks SO much for this great script, Justin. It’s the missing link that has allowed me to transition my workflow from Outlook tasks with attachments on Windows to Outlook on the Mac (required for work) with OF as my task manager. I can’t thank you enough!

    Would it be possible to create a modified version of the script so that the experience is slightly different? Specifically, so that when you run it you get the OF new action window opened up with just the Outlook item as an attachment (without the full text of the outlook item in notes), and the cursor ready to type the name of the new action? This would be good because the name of the action is usually not the same as the subject line of the e-mail. It would also align the experience with the standard OF new action window, and allow the user to assign project/context/start, etc., which has been requested by others on this forum.

    My AppleScript skills are non-existent so I’m putting the request out to you. Again, thanks for the script. I’d been searching high and low for something like this.

    – Dennis

  24. Ross Williamson June 26, 2012 at 6:14 pm #

    Great script use it all the time. There is one feature request – can the created OF item contain a link to the original email. Most often I am creating tasks to emails that I need to provide responses to, and it would be good to be able to click on a link in the email to get back to outlook (like the script you have for Apple Mail to OF)

    Cheers

    Ross

    • Justin Lancy June 26, 2012 at 6:34 pm #

      Hi Ross — Thanks!

      Outlook doesn’t currently allow for “URI Links” to its messages the way Mail does.

      If they add it, so will I! 😀

      • Ross Williamson July 10, 2012 at 6:36 pm #

        Justin,
        Could we then attach a file version of the email to the OF item? Basically so i can then open the attachment and then just reply to the email? Otherwise you have to start a new email to respond to the OF item. Did that make sense?

        Ross

        • Justin Lancy July 11, 2012 at 10:11 am #

          Since Outlook doesn’t allow direct linking, that might be the next best option… I’ll look into it!

  25. Russell July 1, 2012 at 10:57 am #

    Hi this script is fantastic and just what I was looking for however I am new to applescripts and wondered how easy it would be to amend the script so that processed emails were automatically saved in a new folder.

    Thanks
    Russell

  26. Atholl August 4, 2012 at 7:31 am #

    Thanks it worked like a charm

  27. Brad August 29, 2012 at 9:55 pm #

    A really nice feature of the Mac Mail to Evernote script was a custom link back to the original email. Is there a way to enable this functionality in the Outlook 2011 to Evernote script? Great script by the way, saves me a bunch of time!

    • Justin Lancy August 29, 2012 at 10:10 pm #

      Hi Brad,

      Sadly, I believe Outlook doesn’t (currently) have the capability to do this.

      As soon as Microsoft adds it, I will too!

      • Rick September 1, 2012 at 10:50 am #

        Created the script (with scpt AND scptd file extension), putted it in the right folder (made sure by doing it via Outlook>script icon>About>show in finder>.
        After that, restarted outlook. its not showing up in the list with the rest of the scripts ?

        I have the right version of outlook (2011 SP2).
        Why doesnt it show up with the rest of the scripts ?

        • Justin Lancy September 1, 2012 at 12:02 pm #

          Hi Rick,

          In rare cases, another script in that folder will have an issue which prevents any new scripts from appearing in the list.

          Other people have told me that moving all of your scripts out of that folder and adding them back in one at a time is a good way to identify the problem AppleScript. Give it a try and let me know how it works out for you!

          • Rick September 1, 2012 at 12:13 pm #

            Hi Justin,
            Thanks for replying so quickly.
            I just kicked out all scripts except the omnifocus script.
            restarted outlook, nothing showing in the Script menu. Got any idea ?
            Rick.

          • Justin Lancy September 1, 2012 at 12:31 pm #

            The only other thought that occurs to me right now is to:

            1. Open up a new, blank document in AppleScript Editor;
            2. Paste the code from the OmniFocus script into the blank document
            3. Save this “new” AppleScript to the Outlook script folder with a different name.

            … and, of course, all of the usual stuff – Outlook restart, System restart, etc. if it still isn’t showing up!

          • Rick September 1, 2012 at 12:37 pm #

            Justin, this is completely weird, but i followed up on your tip. It worked 😐
            i think it would save a lot of people time, if you could just post the script online instead of copy’n’pastin it 😉

            Thanks for helping out !

  28. Andrée December 31, 2012 at 9:16 am #

    Hi Justin.

    I just started to use Omnifocus and i have all my hundreds of todos in an Exchange enviroment. I tried to find a solution like yours but with no luck until now and it works like a charm. Thanks a million! I will surely check out your other posts and se what i can use.

    Thanks again!

    I wish you a very Happy New Year!

    Best regards

    Andrée

  29. Pablo March 10, 2013 at 1:14 pm #

    Justin, I absolutely love this script!

    Is there a way to stop sending email attachments to OF? I’m using a different system where I store the attachments separately…

    Thanks again for a great thing

    • Justin Lancy March 10, 2013 at 1:24 pm #

      If you want to skip the attachments, I think you can edit out this line with no ill effect:

      if theAttachments is not {} then my message_Attach(theAttachments, theProps, NewTask)

      In future versions, I’ll look at adding a switch to do this.

      • Pablo March 10, 2013 at 1:42 pm #

        I commented it out and it worked – a true/false switch would be nice, but the real kicker would be to have it send to OF the file names that are not included within the body of the text (i.e. as when you reply to someone’s email w/o reattaching the files, but including the names). This would help people to remember which files to look at when they open the todo. Makes sense?

        Cheers and hope Laos is proving fun for you this w/e!

  30. Brian November 13, 2013 at 6:40 pm #

    Hi Justin,

    Thanks for the great script!

    One thing I’d like to be able to do is change the target for the task in OF. Rather than have it go to the general Inbox, I’d like to send it to my Work “inbox” single-action list, since I only use Outlook at work.

    I’d guess I’d change it here…

    set NewTask to make new inbox task with properties {name:OFTitle, note:theContent, flagged:theFlag, due date:theDueDate, completion date:theCompletionDate, start date:theStartDate}

    …but am not sure how to reference the single-action list within the hierarchy. Mine goes like this:
    Library–>Work (folder)–>Work InBox (single-action list).

    Thanks in advance!

  31. paul November 25, 2013 at 2:59 pm #

    Running Outlook 14.3.9
    Omnifocus 1.10.6

    Trying to install the script, but it won’t compile. Fails on the line:

                if raw_Class is calendar event then set the_class to "Calendar"

    Checked the Outlook dictionary, and “calendar event” is a property. For kicks, I commented out the line, then it failed on the next two word property: “incoming message”.

    Any thoughts/ideas?

    • paul November 26, 2013 at 7:42 pm #

      I’ve started to get this working again! Don’t know if it is a Mavericks change or what, but things seem to have seriously changed. It is still not fully tested, so I’m not prepared to send an update yet, but can if others want it and I’ve tested it.

      Also, seems it is always copying in the “content” of an email to task, which will include the HTML. Will look to see if there is a way to put formatted text (HTML) into OmniFocus tasks.

      • Justin Lancy November 26, 2013 at 10:40 pm #

        Hey Paul – Any chance that you updated Outlook to 14.3.9 after the first time you tried to compile the script? (Trying to track down this bug which affects several Outlook scripts on Mavericks)

        • Paul November 27, 2013 at 9:00 am #

          No, I updated outlook first, just tried the script for the first time the other day when I commented.

  32. Nate December 10, 2013 at 12:46 pm #

    There is a similar Applescript written by Lutz Meyer that I have been using for a while with Things that does successfully put a link to the Outlook email in the repository. My Applescript knowledge is non-existent but I’m sure someone could make this work. the code is here:

    https://culturedcode.com/forums/read.php?7,48866,page=1

    This feature is the last remaining thing not implemented by this great script.

    • Justin Lancy December 11, 2013 at 12:04 am #

      Hi Nate,

      Lutz’s script uses a Custom URL Handler to create “virtual links” to items in Outlook. This gets around the fact that Microsoft hasn’t created these links themselves.

      It’s a clever idea and one that I had considered. However this approach may not work for all types of email accounts and, because it is a bit of a hack, I fear it would be one of those things that I’ve learned will cause me a lot of “dain bramage” to keep working over time. Nice thing about AppleScript is, of course, you can always read Lutz’s code and adapt it yourself to any number of scripts. Personally, I’m waiting for the real thing.

      I’d suggest that anyone interested in direct link support (and, if you’re reading this deep into the comments, I expect that you are!) should ping Microsoft and ask them for direct links to Outlook items. You can use their contact page or their Twitter accounts (here and here) to make your wishes known!

  33. Don March 21, 2014 at 4:36 pm #

    Added the script compiled OK. Then saved to the Outlook 2011 script directory but does nothing when i run it.
    I used to have this working great with Omnifocus and 2011 with Growl but had to rebuild. Have not installed growl on the new machine did i miss something ?

  34. Mike May 1, 2014 at 8:56 pm #

    Hi, I am using this with the Omnifocus 2 beta, and it fails to import attachments. The error message is “Item failed to import: 6 Unable to read file from . I have checked the filename and path, and it exists. Any ideas?
    Thanks for the script 🙂

    • Justin Lancy May 2, 2014 at 6:22 am #

      Hi Mike,

      There are some AppleScript changes in OF2, including some specific to the file system in order to sandbox the app.

      You can go ahead and try to make the alterations they suggest now, but I think I’m going to wait to update this script until the dust has settled and OF2 is released.

      • Mike May 5, 2014 at 6:12 pm #

        Thanks, Justin.

  35. Bill Cody June 11, 2014 at 2:40 pm #

    Is there any way to export to the OmniFocus note ONLY a “link” of the Outlook mail message, versus the entire message?

    • Justin Lancy June 11, 2014 at 3:04 pm #

      Hi Bill – Sorry, that’s not currently supported by Outlook.

  36. Chris July 1, 2014 at 2:11 pm #

    Hi Justin–Thanks for the great script. I have a quick question for you: is there any way to add a dialog box that gives me a chance to edit the task that is going into Omnifocus? Or rather, could this script drop the Outlook item into the Omnifocus quick entry window?

    • Justin Lancy July 10, 2014 at 2:37 pm #

      Hi Chris – The nice thing about AppleScript is that *almost everything* becomes customizable! 🙂

      If it’s a critical piece for your workflow, you can always hire me to do a fully customized version for you. If it falls into the “nice to have, but not critical” category, I’ll definitely keep it in mind as I develop new script projects!

      • Chris July 10, 2014 at 2:43 pm #

        Thanks, Justin. I’ll keep that in mind. On another computer I used to have an Applescript that opened the Quick Entry panel, dropped the subject of the email into the task name and the body into the notes section. Of course, I can’t find that script now!

  37. Morag July 4, 2014 at 8:59 am #

    This worked perfectly until I upgraded the OS to 10.9.3. Now it will not work and there are no error messages. Can anyone suggest a fix?

    • Justin Lancy July 10, 2014 at 2:31 pm #

      Anybody else having issues after updating?

  38. Peter Hawkes July 17, 2014 at 9:54 am #

    Is it not possible to add an email link to the OmniFocus entry? The script is excellent but the link back to Original Message when using Mail is difficult to give up!

    • Justin Lancy July 17, 2014 at 11:12 pm #

      Hi Peter (and everyone else asking about email links),

      Outlook doesn’t currently offer a way to do this. Although there are ways to hack a custom email link together, I’m not going there… I’ve seen that they can be finicky and I don’t want to put myself in the position of maintaining it.

      Some good news, though: I reached out to a contact on the Mac team at Microsoft and – though there’s no promises – I think the future looks good for getting something like this added in. As soon as they do, I’ll add it to the script… I promise! 🙂