I am completely brand new to Apple Scripting. I am looking to forward email in Mac Mail. I have created rules that perform this but need to strip the head first, unfortunately unable to do that with just rules. I found the following script that strips the header, but it speaks the email instead of forwarding it.
tell application “Mail”
set selectedMessages to selection
set theBody to (content of item 1 of selectedMessages as rich text)
say theBody with default_voice and waiting until completion
Thanks TecNik. It creates the message to forward in a new window, but it still includes header information. Need to get rid of header and send it automatically. But looks like one step closer.
set MsgSender to "me@domain.com" -- must be configured address, or will default (but still runs fine).
set MsgRecipient to "To@domain.com" -- changed this to valid recipient
tell application "Mail"
set TheMessages to the selection -- this is a list
repeat with current_Message in TheMessages -- individual message
set fwd_Message to forward current_Message with opening window
tell fwd_Message
activate
set sender to MsgSender
set my_recipient to make new to recipient at end of to recipients with properties {address:MsgRecipient}
my grabIt()
end tell
end repeat
end tell
on grabIt()
tell application "System Events" to tell process "Mail"
set frontmost to true
keystroke "a" using {command down}
keystroke "x" using {command down}
end tell
delay 0.5
tell application "TextEdit"
activate
set tEditDoc to make new document
end tell
tell application "System Events" to tell process "TextEdit"
set frontmost to true
keystroke "v" using {command down}
end tell
tell application "TextEdit" to tell tEditDoc
delete (paragraphs 1 thru 10)
end tell
set the clipboard to ""
tell application "System Events" to tell process "TextEdit"
set frontmost to true
keystroke "a" using {command down}
keystroke "c" using {command down}
end tell
delay 0.5
tell application "TextEdit"
close tEditDoc without saving
end tell
tell application "Mail" to activate
tell application "System Events" to tell process "Mail"
set frontmost to true
keystroke "a" using {command down}
keystroke "v" using {command down}
end tell
end grabIt
Yvan KOENIG (VALLAURIS, France) mercredi 10 juin 2015 17:20:02