set _filename to "Reports"
set _dateStamp to (do shell script "date +_%Y-%m-%d_%H.%M.%S")
set _newName to _filename & _dateStamp & ".pdf"
tell application "System Events"
set appname to name of first process whose frontmost is true
end tell
if appname is "AppleScript Editor" then set appname to "Safari"
activate application appname
tell application "System Events"
tell process appname
set nbw to count windows
-- insert GUI Scripting statements here
keystroke "p" using {command down}
(*
Wait for the availability of the sheet *)
repeat
if exists sheet 1 of window 1 then exit repeat
end repeat
set PDFButton to first menu button of sheet 1 of window 1
click PDFButton
click menu item 2 of menu 1 of PDFButton
(*
Wait for the availability of the Print sheet *)
repeat
if exists sheet 1 of sheet 1 of window 1 then exit repeat
end repeat
(*
Force Desktop as target folder *)
keystroke "d" using {command down}
(*
Set the name of the new PDF *)
set value of text field 1 of sheet 1 of sheet 1 of window 1 to _newName
keystroke return
end tell
end tell