清理 Outlook 裡面重複的信件

假如 outlook 每次都把以前備份的信件匯入, 那麼信箱裡就會塞滿很多重複的信件, 假如是使用 exchange 的話, 還會有很多重複的聯絡人, 會議等等, 相當地佔記憶體.

Windows 的用戶可以上網去抓一些免費的小工具, 但是 Mac 的用戶就比較辛苦了. 看來看去, Barry's Applecripts 不失為一個沒辦法中的選擇. 首先把有很多重複 mail 的 Outlook 信箱選起來 (select/select all), 然後在 AppleScript 編寫程式裡面選 "執行" 就可以了. 

當然, 最好是先備份一下, 以免誤殺義士, 還要把紫微拋入深谷~~

— Remove Duplicate Message v2.1

— An Applescript by Barry Wainwright, 15th October 2010

— Detects and deletes duplicate messages within a selected folder

— works on Message-ID header – uniquely identifying duplicates


— Version History

— v1.0 – 2002-03-18: First Release (For Microsoft Entourage)

— v2.0 – 2010-10-07: modified to work with Microsoft Outlook for Mac

— v2.1 – 2010-10-15: added final dialog to summarise messages removed


tell application "Microsoft Outlook"

set theMessages to current messages

if theMessages = {} then

try

set theFolder to selected folder

set mb to theFolder

on error

display dialog "In the folder listing, please select the folder you want to be scanned for duplicates" with icon stop buttons {"Quit"} default button 1

return -99

end try

else

set mb to folder of item 1 of theMessages

end if

set theName to name of mb

say "Removing duplicates from mail folder: " & theName

set y to count messages of mb

say "Number of messages to check, " & y

set IDlist to {}

repeat with x from y to 1 by -1

try

set theHeaders to (get headers of message x of mb)

set AppleScript's text item delimiters to {return & "Message-"}

set temp to text item 2 of theHeaders

set AppleScript's text item delimiters to {return}

set theId to text 5 through -1 of text item 1 of temp

on error

set theId to ""

end try

if theId is in my IDlist then

delete message x of mb

else if theId ≠ "" then

copy theId to end of IDlist

end if

if x mod 100 = 0 then say "" & x

end repeat

set removedCount to y – (count messages of mb)

if removedCount is 0 then

say "Finished. No duplicates detected"

else

say "Finished. " & removedCount & " duplicates removed"

end if

display dialog "" & y & " messages checked" & return & removedCount & " messages removed" buttons {"OK"} default button 1

set AppleScript's text item delimiters to {""}

end tell


對了!這個 script 是會說話的, 我本來還以為我幻聽了…原來是音量開得太小聲, 難怪一直聽到斷斷續續的人聲, 再猛一聽又沒了….:/. 如果不想聽到聲音的話, 用 — 把 say mark 掉就行了.
 
2011/12/26 補充

太久沒用, 我都忘記 Apple Script 在哪裡了?首先進到 Finder 的工具程式, 再點選 Apple Script 編輯程式的 App. 把上面的 script 貼上去, 按執行就可以了!
 
如果 folder 太大, 確實有 time out 的危險. 按 command + option + shift + ESC 三秒鐘可以停掉當前 active 的程式.
 
2011/12/28 補充
 
因為這個 script 太慢了, 我想了一下. 畢竟相同的 mail 應該都是同一個時間, 主旨, 寄件人等等. 所以不論怎麼 sorting, 這些信都會連在一起. 所以不需要搜尋整個 IDList, 只要看到未見過的 theId 就把 IDList 清掉就好了. 我加了一行, 底色標成黃色.
 

if theId is in my IDlist then

delete message x of mb

else if theId ≠ "" then

set IDlist to {}

copy theId to end of IDlist

end if


要解決 time out 的問題, 把 tell 到 end tell 裡面用 time out 包起來就可以了. Time out  只能以秒為單位.

tell application "Microsoft Outlook"

with timeout of 1000000 seconds
end timeout
end tell

最近發現的小技巧

我的 Office for Mac 用起來還 OK, 但是有一件事情非常困擾我. 那就是只要打開 spelling and grammar check, Word 裡面就是滿江紅!而且它建議我改的字, 都是些我不認識的, 只有極少數不會被畫上紅色的波浪底線. 這麼一來, 真正拼錯的字就找不出來了!

我本來以為是字典的問題, 或是語言設定的問題, 又或者是使用者自定字典 (custom dictionary) 引起的? 不過今天我赫然發現, 原來一切都是荷蘭人惹的禍!!! 我這個 Word 所打開的第一份文件就是荷蘭人寫的, 所以 Word 就自動把荷蘭文寫進 normal.dot. 從此以後, 它就自動以荷蘭文為標準來檢查我的拼字. 這個問題在我 select all –> 選 tool/language/English(US) –> 選 default 之後就測底解決了. 這麼怪異的 bug, 難怪我在網路上都找不到解答!

另外一個發現是我重灌 word press, 也就是我的部落格的時候. 發現 2.5.X 和 2.6.X 都不認識 Windows Vista. 雖然看似安裝起來了, 但是進到 phpMyAdmin 就出不來了. 無奈之下只好去裝 2.4.9 版, 僅僅比 2007 年建部落格時用的 2.4.5 版高級一點點而已. 但 2.4 支持 PHP4, 2.5 支持 PHP5, 2.6 支持 PHP6, 不相容也勉強不來. 此外, 雖然書上書, 安裝部落格的時候, 在 Appserv 這個套件裡面要輸入 Web server 的 IP, 而且 IP = localhost = 127.0.0.1.  但對於 PPPoE 撥接的人可不是這樣.

假設我向中華電信申請了一個固定 IP: 1.2.3.4. 撥接上去之後, PC 看到自己的 IP 並非這個值, 而是內部虛擬的另外一個 IP, 比方說: 9.8.7.6, 所以在 AppServ 裡面固然要填第一個 1.2.3.4 的 IP, 但不要以為 localhost 就是它, localhost 是 9.8.7.6. 如果要進入 phpMyAdmin, 就要指定 9.8.7.6 才對, 我試過用外網的 IP 或是 localhost 都看不到東西.

這樣裝起來之後, 不需要 port forwarding 也可以在本機編輯自己的 blog. 當然, 此時還要執行動態 IP 程式, 先告訴 DNS http://www.cash.idv.tw = 1.2.3.4 才能用 domain name 代替 IP address. 以上就是最近兩三天的新發現, 希望對大家有用.

對了! 以安裝 Apache 的套件來說, Xamp 雖然比較酷炫, 但是 AppServ 還是不錯用. 幸好有這些好心人提供免費軟體, 我們才能省下大把的時間. 雖然利用套件還是有很多要摸索的地方, 但時光若倒退 30 年, 能架 httpd server 的人就是高手高手高高手, 或許可以進 FBI 工作了. 更遑論複雜地多的 blog,  若不是累積眾人的智慧也無法變得如此普及. 往好處想, 我們能享受科技帶來的便利真是幸福~~~

重裝 Office for Mac 的小技巧

首先, 講一下很多人為之頭痛的 syncServiceAgent 問題. 很多人重裝 Office 2011 for Mac, 到了最後兩分鐘的時候, 安裝程式才開始抱怨: 有一個 syncServiceAgent 正在執行, 所以無法繼續安裝. 許多老外因此而氣得抓狂, 有人提供了要花一小時才能關掉 syncServiceAgent 的 “TIPS", 感動的網友 Haakon 竟然說:"Anthony. You can marry my daughter any day. IT WORKED! after 1 hour trying to shut the damn thing down. THANK YOU" 可見生女兒真的比較不值錢~~~呃! 我是說大家都氣瘋了!

但其實這個很簡單, Mac 的工具程式裡面有活動監視器, 類似 Windows 的工作管理員. 找到 syncServiceAgent 之後, 就選擇結束它!然後….它又立刻生出來了!不過 Mac 很貼心地把它的老爸也秀出來, 只要把它的老爸 launchd 也殺了, syncServiceAgent 沒辦法很快再生出來. 此時趕快按 install 程式的 “繼續", 就可以把最後兩分鐘安裝完!

當然, 事情會搞得這麼困擾, 就是因為沒有把前一版的 Office 解除安裝. 想要把它徹底 uninstall, 在 2008 年版只要執行 uninstall 就可以了!但是 2011 版就是少了這個反安裝程式, 搞得大家都很辛苦. 一如 N 年前我上 Synopsys Synthesis 課程的時候, 講師說: 這步做錯了怎麼辦?我立刻說 “undo", 講師苦笑說:沒有 undo. 真的想把 Office 2011 for Mac 殺乾淨, 可以參考這一篇:http://support.microsoft.com/kb/2398768/en-us

不過, 上述的殺法雖然很徹底. 如果想要重新安裝, 那麼千萬不要把 step 6 的 Microsoft User Data folder 殺掉. 一定要先備份起來. 到時候把 data copy 到 microsoft user data / office 2011 identities / Main indentity / Data Records 下面, 然後選和 Data Records 同層的 Database, 再選打開, rebuild database, 就可以把陳年舊帳 merge 回去.