Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am not working on an Apple computer, but I know people who do. I want to create a shell script for them which allows them to create a larger number of messages automatically. It should look like this:

function mymail {
  Mail ....  

mymail "" "subject1" "message text" "attachment.txt"

Can I pass commandline arguments to Apple Mail in the mymail function which will allow me to create these messages from the shell? The mailer should not actually send the messages. It should just display message windows or save them in some folder to be reviewed by the sender.

share|improve this question

I haven't really tested this, but you could use AppleScript for it.

mymail() {
    osascript - "$@" <<-END
on run args
tell app "Mail"
set m to make new outgoing message with properties {subject:item 2 of args, content:item 3 of args, visible:true}
tell m
make new to recipient at end of to recipients with properties {address:item 1 of args}
if number of args is 4
make new attachment with properties {file name:POSIX file (item 4 of args)} at after last paragraph
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.