Created
February 5, 2011 13:00
-
-
Save osa9/812436 to your computer and use it in GitHub Desktop.
Apple MailでTwitterのフォロー通知メールが届いた時にGrowlで通知
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Growlにアプリケーションを登録 *) | |
tell application "GrowlHelperApp" | |
register as application ¬ | |
"TWMailGrowl" all notifications {"Notification", "Notification2"} ¬ | |
default notifications {"Notification"} ¬ | |
icon of application "Script Editor" | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Apple MailでTwitterのフォロー通知メールが届いた時に | |
このスクリプトを呼び出すようにしておけば,Growlで通知してくれます. | |
フォローした人のアイコンも表示されます(たぶん) | |
動作のためにはnkfが必要です. | |
設定方法: | |
Apple Mailの「環境設定>ルール」のタブで, | |
ついったーからフォローメールが来た時にこのスクリプトを呼び出すようにする. | |
私が使っているルール: | |
差し出し人 「@postmaster.twitter.com」 を含む | |
件名 「あなたをフォローし始めました」を含む | |
アクション: | |
Apple Scriptを実行 (このファイル) | |
開封済みにする | |
尚,実行は自己責任でよろしくお願い致します. | |
*) | |
(* | |
Growlへのアプリケーション登録用スクリプト: | |
以下の内容を記述したファイルにGrowlRegist.scptとでも名前を付けて実行してください. | |
tell application "GrowlHelperApp" | |
register as application ¬ | |
"TWMailGrowl" all notifications {"Notification", "Notification2"} ¬ | |
default notifications {"Notification"} ¬ | |
icon of application "Script Editor" | |
end tell | |
*) | |
(* メール用ルール *) | |
using terms from application "Mail" | |
on perform mail action with messages theMessages for rule theRule | |
tell application "Mail" | |
repeat with eachMessage in theMessages | |
set theHeaders to (headers of eachMessage) | |
repeat with eachHeader in theHeaders | |
tell eachHeader | |
if name is "x-twittersenderscreenname" then | |
set theScreen to content | |
else if name is "x-twittersendername" then | |
set theName to content | |
end if | |
end tell | |
end repeat | |
try | |
set theIconpath to getIcon(source of eachMessage) of me | |
set theText to theName & "(@" & theScreen & ")にフォローされました" | |
log (theText) | |
log (theIconpath) | |
Notify(theText, theIconpath) of me | |
end try | |
end repeat | |
end tell | |
end perform mail action with messages | |
end using terms from | |
(* メール本文からアイコンURLを取得して/tmp/に保存 *) | |
on getIcon(theContent) | |
set theGrep to "http://[0-9a-z]+.twimg.com/profile_images/[^\"\\s]+" | |
try | |
return do shell script ¬ | |
"u=`echo '" & theContent & "' | nkf -mQWs | grep -Po -m 1 --binary-files=text '" & theGrep & "'`;" & ¬ | |
"f=`echo $u | grep -Po '[0-9a-zA-Z\\._]+$'`;" & ¬ | |
"wget -O /tmp/$f \"$u\" > /dev/null 2>&1 ;" & "echo file:///tmp/$f" | |
end try | |
return "" | |
end getIcon | |
on Notify(theMessage, theImage) | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Notification" title ¬ | |
"Twitter" description theMessage ¬ | |
application name ¬ | |
"TWMailGrowl" image from location theImage | |
end tell | |
end Notify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment