2007-03-02
AppleのMail.appでbloglines読むのが溜まりすぎたので、既読を削除するAppleScript書いた
bloglinesをGmailで読んでいたけど、スピードが遅いのでMail.appに変えて数ヶ月。そろそろ読んだメールが10万通を超えたので削除することに。
いままでも適度に手作業で削除していたけど、あんまり大量に溜まると選択するだけでも凄い時間がかかるので。
あと何でかよく分からんが、Mail.appのルールには「メッセージを読んだ」という項目がないので、ルールで自動的にゴミ箱に入れる事が出来ない。ダサい。
AutomatorのMail.appバインドのフィルターには有るのだが。でもAppleEvent経由でメッセージを取り出して、そこにフィルターをかけるので10万通だとタイムアウトしてしまう。
ということで、ルールで「すべてのメッセージ」を以下のAppleScriptを実行することで対処。
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" set selCount to (count of theMessages) repeat with counter from 1 to selCount set msg to item counter of theMessages if (read status of msg) is true then delete msg end if end repeat end tell end perform mail action with messages end using terms from
本当は
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" repeat with eachMessage in theMessages try if (read status of eachMessage) is true then delete eachMessage end if end try end repeat end tell end perform mail action with messages end using terms from
でも良いはずなんだけど。
追記
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" set max_value to number of items in theMessages repeat with i from 1 to max_value set this_item to item i of theMessages if (read status of this_item) then delete this_item end if end repeat end tell end perform mail action with messages end using terms from
item n of theMessagesからid参照を引くのが重いので、ループ中は一回で済むようにした。
コメント
トラックバック - http://subtech.g.hatena.ne.jp/otsune/20070302
