Apologies if this is a fairly novice question but I’m still stumped after looking online for a while (I’m new to Applescript).
I’m trying to automate a setup in Apple Mail for our institutions IMAP and SMTP server. Thing is if there is already an account present in Apple Mail, the script works fine (with the exception of passing passwords through the script, but this is not a major issue as this can be entered when opening Apple Mail).
If there is no account whatsoever already present in Apple Mail the script just dies and the ‘Welcome to Mail’ dialogue setup wizard appears.
Is there anyway to bypass this?
Many thanks for any help.
I’d use the defaults read com.apple.mail, before telling mail to do anything, and there check for keys that should be set if mail are set up. run diff from defaults read, and see the keys that should be set for accounts, when it is configured. Later on, you can run that defaults read command with the appropriate key, to see if it is pristine or not.
See man defaults, and any man page referenced from there, in a terminal window.
the folder ~/Library/Mail/V2/Mailboxes is empty if there are no accounts defined.
V2/Mailboxes is the folder path of 10.8. In Lion and lower the path might be different
tell application "System Events"
set mailHasNoAccounts to count (items of folder "Mail/V2/Mailboxes" of library folder of user domain) = 0