Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 "recipient1@mail.com" "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
add comment

1 Answer

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
end
end
activate
end
end
END
}
share|improve this answer
add comment

Your Answer

 
discard

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.