set msgFile to alias "OS_X:Users:lutherfuller:Desktop:UI scripts:Kids Book Sale -- 4 Days Only! 0.emlx"
tell application "Mail"
activate
close every window
set download html attachments to true
open msgFile
set download html attachments to false
set winName to (name of window 1)
-- close window winName -- this command works here, but ...
delay 1
-------------------
tell application "System Events"
-- UI elements enabled is true. Set manually.
tell process "Mail"
keystroke "p" using {command down}
delay 1
click menu button "PDF" of sheet 1 of window 1
delay 1
click menu item "Save as PDF…" of menu of menu button "PDF" of sheet 1 of window 1
delay 1
click button "Save" of window "Save" -- save location has been manually set to Desktop
end tell
end tell
-------------------
close window winName -- but this command does NOT work.
end tell
But ...
On Mar 5, 2010, at 11:10 AM, Bill Cheeseman wrote:
That will get you the Save panel, where I expect you'll be doing some more scripting. There used to be problems with the accessibility API, and therefore with GUI Scripting, in Save panels. Good luck.
Notice that I did not try to change the save location. And I don't think I will even try. I wrote this script as a feasibility study for a new feature for another application. The pdf must be saved to the container of the file referenced by the alias msgFile, above. And it has to work properly, every time, on your computer, not mine. I doubt that scripting the location for Save would be reliable.
Considering the universal usefulness of PDF documents, there ought to be a command, in AppleScript or StandardAdditions, that works like this ...
savepdf document <file alias> using application <application specifier> to <location specifier>
Using this, a document named "Kids Book Sale -- 4 Days Only! 0.pdf" would appear in the folder "OS_X:Users:lutherfuller:Desktop:UI scripts:". The script above could be done with ...
savepdf document msgFile using application "Mail" to (container of msgFile)
Simple!