Created
September 8, 2010 13:37
-
-
Save evadne/570133 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- In Mail, create a new rule, then add “Run AppleScript” to the list of actions to perform. Notice that the buddy name and the service index are both hard-coded. | |
using terms from application "Mail" | |
on perform mail action with messages newMessages for rule theRule | |
repeat with newMessage in newMessages | |
set senderName to (extract name from sender of newMessage) | |
set subjectText to (subject of newMessage) | |
set contentText to (content of newMessage) | |
set excerptText to contentText | |
set excerptText to replaceText(ASCII character 10, " ", excerptText) | |
set excerptText to replaceText(ASCII character 13, " ", excerptText) | |
set excerptText to truncateString(excerptText, 65) | |
tell application "iChat" | |
send (senderName & ": " & subjectText & " — " & excerptText & (ASCII character 10) & (ASCII character 13) & "—" & (ASCII character 10) & (ASCII character 13) & contentText) to buddy "[email protected]" of service 2 | |
end tell | |
end repeat | |
end perform mail action with messages | |
end using terms from | |
on replaceText(find, replace, someText) | |
set prevTIDs to text item delimiters of AppleScript | |
set text item delimiters of AppleScript to find | |
set someText to text items of someText | |
set text item delimiters of AppleScript to replace | |
set someText to "" & someText | |
set text item delimiters of AppleScript to prevTIDs | |
return someText | |
end replaceText | |
on truncateString(txt, max) | |
set txtLength to (length of txt) | |
if txtLength > max then | |
set txt to (text 1 thru (max - 1) of txt) & "" as string | |
set txt to txt & "… " | |
end if | |
return txt | |
end truncateString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment