Select the save format in the Save As dialog by using AppleScript

applescript

How do I select the output format in the Save As dialog of Mail.app? I know how to change the file name by using keystroke but I could not figure out how to change the file format in AppleScript.

enter image description here

Best Answer

Assuming Mail has focus and the Save As sheet is showing, then the following example AppleScript code would click the Format: pop up menu and select e.g.: Plain Text

tell application "System Events"
    tell application process "Mail"
        tell sheet 1 of window 1
            tell pop up button 2
                click
                click menu item "Plain Text" of menu 1
            end tell
        end tell
    end tell
end tell

You can also use the menu item number, e.g. click menu item 3 of menu 1


Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.