Skip to content

Instantly share code, notes, and snippets.

@masnick
Created October 15, 2013 01:30
Show Gist options
  • Save masnick/6985205 to your computer and use it in GitHub Desktop.
Save masnick/6985205 to your computer and use it in GitHub Desktop.
Create an email message in Mail.app with this AppleScript. Callable from the Terminal.
on replace(input, find, replacement)
set text item delimiters to find
set ti to text items of input
set text item delimiters to replacement
ti as text
end replace
--Variables
on run argv
set recipientName to item 1 of argv
set recipientAddress to item 2 of argv
set theSubject to item 3 of argv
set theContent to item 4 of argv
set theContent to replace(theContent, "\\n", return)
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Send the Message
--send
save
close
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment