tell application "System Events"
tell process "Mail"
set frontmost to true
-------------------------
keystroke "p" using {command down} -- opens Print dialog
repeat 20 times -- wait for print sheet to appear
delay 1
set frontmost to true
if exists sheet 1 of window 1 then exit repeat
end repeat
if not (exists sheet 1 of window 1) then error "Mail is not responding. The Print dialog failed to appear."
set frontmost to true
---------------------------------
set PDFButton to (first menu button of sheet 1 of window 1)
click PDFButton
click menu item 2 of menu 1 of PDFButton -- Save as PDF...
delay 2 -- wait for the Save window
set value of text field 1 of window 1 to "tempFile.pdf" --***** ERROR HERE IN MT LION ********
---------------------------------
keystroke return -- click button "Save" of sheet 1 of window 1
end tell
end tell