Auto Replacement of Existing File when saving mail in mail.app

Hi guys,

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?

Thanx!

This seems to work.


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

Cheers!

Craig

Hi Craig,

thanx for the script! It works perfectly

one qn though, how do i know which window is sheet 1 and window 1?

I’m assuming that sheet 1 is my inbox and window 1 is the top most window in my screen, I’m I correct?

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.

Glad I could help!

Craig