I am planning to automate the archive my mails using the “Save As” menu option in Mail.app
However, I found out that Mail.app will by default assume the Subject of the mail to be the filename. I’m totally fine with that.
so I created a script to run through all the mails and use
keystroke “s” using {command down, shift down}
to save the mail
But, alas, if the mail happens to be of the same subject, mail.app will pop another dialog box to ask whether to replace.
Is there anyway to bypass this dialog box?
Or automatically select the Replace button?
activate application "Mail"
tell application "System Events"
tell process "Mail"
keystroke "s" using {command down, shift down}
delay 0.5
click button "Save" of sheet 1 of window 1
delay 0.5
try
click button "Replace" of sheet 1 of sheet 1 of window 1
click button "Save" of sheet 1 of window 1
end try
end tell
end tell
Sheet 1 is what comes down out of the top of window 1 giving you the
dialog to save the email. When the additional Sheet comes
out of that window it says Sheet 1 of Sheet 1 of Window 1.
If you end up doing a lot of GUI scripting you might look into
UI Browser. It makes GUI scripting much easier.