Applescript to find all occurencies of a eMail address in Outlooks 2011 Contacts and replace.

set oldaddress to "asdf@asdf.com"
set newaddress to "qwer@asdf.com"

tell application "/Applications/Microsoft Office 2011/Microsoft Outlook.app"
    set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
    set theContactIDs to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & " 'kMDItemContentType == com.microsoft.outlook14.contact && kMDItemEmailAddresses == " & oldaddress & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")
    
    set theContacts to {}
    repeat with thisContactID in theContactIDs
        set theaddresses to email addresses of contact id thisContactID
        repeat with theaddress in theaddresses
            set address of theaddress to newaddress
        end repeat
        set email addresses of (item 1 of contact id thisContactID) to theaddresses
    end repeat
end tell

Leave a Reply

Your email address will not be published. Required fields are marked *