Change in Gui Commands

Just switched to Mountain Lion and a script that used to process emails no longer works. I have a handler as part of the routine that saves the message as a PDF file .

I extracted the handler as a standalone script and opened an email and ran it. The print dialog box opens and then it hangs telling "Sheet1 of Windows 1 of process “Mail” is false. As the dialog is open that does not make sense unless the object descriptions are incorrect.

This is the script any help greatly appreciated.

tell application "System Events"
	tell process "Mail"
		keystroke "p" using command down
		repeat until exists sheet 1 of window 1
			delay 0.2
		end repeat
		tell sheet 1 of window 1
			click menu button "PDF"
			repeat until exists menu 1 of menu button "PDF"
				delay 0.02
			end repeat
			click menu item "Save as PDF." of menu 1 of menu button "PDF"
		end tell
	end tell
end tell

Peter

Model: iMac 27
AppleScript: 2.5(138)
Browser: Safari 536.26.14
Operating System: Mac OS X (10.8)

Fixed that problem with tell block to call mail first. Now I cannot get GUI to select a menu item.
This is the handler I I included the error message below the call that causes the problem.

on FileasPDF()
	tell application "Mail"
		activate
	end tell
	tell application "System Events"
		tell process "Mail"
			keystroke "p" using command down
			repeat until exists sheet 1 of window 1
				delay 0.2
			end repeat
			display dialog "Exists sheet1 of window 1"
			tell sheet 1 of window 1
				click menu button "PDF"
				repeat until exists menu 1 of menu button "PDF"
					delay 0.02
				end repeat
				display dialog "Exists menu 1 of menu button PDF"
				
				click menu item "Save as PDF." of menu 1 of menu button "PDF"
				--error "System Events got an error: Can't get menu 1 of menu button \"PDF\" of sheet 1 of window 1 of process \"Mail\". Invalid index." number -1719 from menu 1 of menu button "PDF" of sheet 1 of window 1 of process "Mail"
				
			end tell
			repeat until exists window "Save"
				delay 0.2
			end repeat
			tell window "Save"
				keystroke "g" using {command down, shift down}
				repeat until exists sheet 1
					delay 0.2
				end repeat
				tell sheet 1
					--Subject_Added Peter to test how to pass file name
					set value of text field 1 to POSIX path of destinationFolder & "/" & Subject_
					click button "Go"
				end tell
				repeat while exists sheet 1
					delay 0.2
				end repeat
				click button "Save"
			end tell
		end tell
	end tell
end FileasPDF

Any suggestions please.

Peter

Just get rid of your “display dialog” commands. They are taking focus away from the objects you want to click and thus causing the error.

Hi Hank

Thanks for the advice I had put them in to debug the first problem the moment I commented them out it worked as you suggested but only down to the next repeat. It cannot see the Window “Save” I have tried “Save As” and Save As:". As I mentioned in my earlier post this whole routine was working fine before the upgrade to Mountain Lion so I wonder if the names of the windows have changed.

Thanks you again any ideas would be appreciated.

Peter

I guess that it would behave correctly if you use the correct item name which is : “Save As.” (Yes, the ellipsis character).

Yvan KOENIG (VALLAURIS, France) jeudi 22 novembre 2012 15:18:14

Hi Yvan

Thanks for the reply tried that and it did not help. It is the window/sheet not sure which I need to address. You may have noticed earlier in the routine I used “Save As PDF…” which then opens the save window and it is on that window I want to Activate the “Save” button but first I need the routine to recognize that the Save window is open".
I have tried to determine the name of the save window but all the command below returns is the name of the window that the “Save as PDF…” was called from.

tell application "System Events" to get the title of every window of process "Mail"

Thanks again

Peter

They are all sheets now so you can’t be telling any “window”. Try this…

on FileasPDF()
	tell application "Mail"
		activate
	end tell
	tell application "System Events"
		tell process "Mail"
			keystroke "p" using command down
			repeat until exists sheet 1 of window 1
				delay 0.2
			end repeat
			
			tell sheet 1 of window 1
				click menu button "PDF"
				repeat until exists menu 1 of menu button "PDF"
					delay 0.02
				end repeat
				
				click menu item "Save as PDF." of menu 1 of menu button "PDF"
				
			end tell
			
			repeat until exists (sheet 1 of sheet 1 of window 1)
				delay 0.2
			end repeat
			
			keystroke "g" using {command down, shift down}
			repeat until exists sheet 1 of sheet 1 of sheet 1 of window 1
				delay 0.2
			end repeat
			
			tell sheet 1 of sheet 1 of sheet 1 of window 1
				set value of text field 1 to POSIX path of (destinationFolder & "/" & Subject_)
				click button "Go"
			end tell
			
			repeat while exists sheet 1 of sheet 1 of sheet 1 of window 1
				delay 0.2
			end repeat
			
			tell sheet 1 of sheet 1 of window 1
				click button "Save"
			end tell
		end tell
	end tell
end FileasPDF

Hi

Cannot thank you enough :slight_smile: one minor change I no longer need the POSIX path, changed that and the whole scrip is now working again, at least I hope so.

Peter