Way to Configure AppleMail without user seeing it launch?

Anyone know if there’s a way to configure AppleMail via AppleScript without having the user see AppleMail launch? For instance, I’ve got a script that will add a new AppleMail account, but it launches AppleMail in order to do it, and if the user has to enter a password for one of the accounts already in AppleMail, a popup appears. I’d like to see if there’s a way to “invisibly” add an account to AppleMail.

  • Rob

If the script includes a ‘tell application “Mail”’, I don’t see any way to stop it from launching. You can launch it and hide it.

tell application "Mail" to launch
tell application "System Events" to set visible of process "Mail" to false

It might be possible to add an account by manipulating preference files but I have no idea on how that might be done.

:frowning: Well, this does hide AppleMail, but if the user has not previously set an email account, it still pops up the “you need to set up an account” dialog box, and halts all my other scripts. My hope is to add an account to AppleMail - - - but if the launching process gets halted by the popup to add an account, that messes up my plans. If this can’t be done via applescript, does anyone know where AppleMail stores it’s accountdata? In an XML file somewhere?

It looks like it’s in: ~/Library/Preferences/com.apple.mail.plist

You might be able to use AppleScript and the shell’s ‘defaults’ to read and write the file. I don’t have enough knowledge on the topic to share. To read the ‘defaults’ manual in Terminal, run: man defaults

As Rob points out, you can use the terminal to read the com.apple.mail.plist file by typing this command in the terminal.

defaults read com.apple.mail

Or leaving the Terminal out of it, using AppleScript, this will read the account info of the file:

set mailAccts to do shell script "defaults read com.apple.mail MailAccounts"

Is there a way in Applescript to tell AppleMail to “press the Quit button”, on the popup that AppleMail displays the very first time you use it, when it has no accounts defined. (It prompts you to either configure an account, or quit). Doing a “tell application Mail to quit” does not over-ride this popup, unforunately.

I thought I had read somewhere that Applescript now permits full-control over individual elements of a UI (like button-pressing and pulling data out of fields, etc). I could be wrong.

Yes, AppleScript’s latest vesion of the Script Editor, UI Element Inspector, and System Events are available at UI Scripting
You may also want to check our PreFab’s UI Browser which will help you determine the various UI Elements available for windows, menu’s, and almost evey other aspect of UI Scripting. Take a look at PreFab’s comparison of Apple’s free UI Element Inspector versus their UI Browser.