May you try to run this script with the Log History window open ?
set SaveFolder to (path to desktop folder) as text
set SaveFolder to POSIX path of SaveFolder
set pdfName to "TestResults.pdf"
set fullPath to SaveFolder & pdfName
tell application "System Events"
if exists file fullPath then delete file fullPath
end tell
--display dialog SaveFolder
set theApp to "Safari" -- I code this way because all the rest of the script is the same for every application
tell application theApp to activate
tell application "System Events"
tell process theApp
keystroke "p" using {command down} -- activate print menu item
tell window 1
repeat until exists sheet 1
delay 0.02
end repeat
tell sheet 1
class of UI elements --> {group, static text, group, static text, pop up button, static text, pop up button, static text, text field, checkbox, static text, radio button, radio button, text field, static text, text field, static text, pop up button, static text, static text, radio group, static text, text field, pop up button, checkbox, checkbox, button, menu button, button, button, button}
description of pop up buttons --> {"Imprimantes", "Préréglages", "Taille du papier", "PDE"}
title of menu buttons
tell menu button "PDF"
get its value --> missing value
click it
repeat until exists menu 1
delay 0.02
end repeat
get its value --> missing value
name of menu items of menu 1 --> {"Ouvrir dans Aperçu", "Enregistrer au format PDF", "Enregistrer au format PostScript", missing value, "@ PDF-BAT.qfilter", "@ PDF-prépresse CMJN.qfilter", "@ PDF-web.qfilter", "@ PDFX3-ISO.qfilter", "Ajouter à iBooks", "Save as Adobe PDF", "Enregistrer en PDF-X", "Save PDF to Aperture", "Save PDF to folder as JPEG", "Save PDF to folder as TIFF", "Enregistrer le document PDF vers iPhoto", "Enregistrer sur iCloud Drive", "Enregistrer avec les reçus web", "Envoyer via Mail", "Envoyer via Messages", "Copie de AbracadabraPDF-web.qfilter", missing value, "Modifier le menu…"}
click menu item 2 of menu 1 -- "Save as PDF"
end tell -- menu button "PDF"
keystroke "g" using {shift down, command down} -- to select the folder location
repeat until exists sheet 1
delay 0.02
end repeat
tell sheet 1
repeat until exists sheet 1
delay 0.02
end repeat
tell sheet 1
set theClasses to class of UI elements --> {static text, combo box, button, button}
name of buttons --> {"Aller", "Annuler"}
if theClasses contains combo box then
set value of combo box 1 to SaveFolder -- modern systems no longer use a text field here
else
set value of text field 1 to SaveFolder
end if
click button 1 --> "Aller"
end tell -- sheet 1
repeat while exists sheet 1
delay 0.02
end repeat
class of UI elements --> {static text, text field, UI element, static text, text field, group, radio group, group, pop up button, text field, splitter group, text field, static text, button, text field, static text, text field, static text, static text, text field, button, button, button}
name of text fields --> {"Enregistrer sous :", "Tags :", missing value, missing value, missing value, missing value, missing value}
set value of text field 1 to pdfName
name of buttons --> {"Options de sécurité…", "Nouveau dossier", "Annuler", "Enregistrer"}
name of button -1 --> "Enregistrer"
click button -1
end tell -- sheet 1
end tell -- sheet 1
end tell -- window 1
end tell
end tell
Here the log history is :
Don't click upon [Open this Scriplet in your Editor:], here is just a log history
tell current application
path to desktop
--> alias "SSD 1000:Users:**********:Desktop:"
end tell
tell application "System Events"
exists file "/Users/**********/Desktop/TestResults.pdf"
--> true
delete file "/Users/**********/Desktop/TestResults.pdf"
end tell
tell application "Safari"
activate
end tell
tell application "System Events"
keystroke "p" using {command down}
exists sheet 1 of window 1 of process "Safari"
--> true
get class of every UI element of sheet 1 of window 1 of process "Safari"
--> {group, static text, group, static text, pop up button, static text, pop up button, static text, text field, checkbox, static text, radio button, radio button, text field, static text, text field, static text, pop up button, static text, static text, radio group, static text, text field, pop up button, checkbox, checkbox, button, menu button, button, button, button}
get description of every pop up button of sheet 1 of window 1 of process "Safari"
--> {"Imprimantes", "Préréglages", "Taille du papier", "PDE"}
get title of every menu button of sheet 1 of window 1 of process "Safari"
--> {"PDF"}
get value of menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> missing value
click menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> menu button "PDF" of sheet 1 of window "MacScripter / Save Web Pages as PDF's" of application process "Safari"
exists menu 1 of menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> true
get value of menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> missing value
get name of every menu item of menu 1 of menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> {"Ouvrir dans Aperçu", "Enregistrer au format PDF", "Enregistrer au format PostScript", missing value, "@ PDF-BAT.qfilter", "@ PDF-prépresse CMJN.qfilter", "@ PDF-web.qfilter", "@ PDFX3-ISO.qfilter", "Ajouter à iBooks", "Save as Adobe PDF", "Enregistrer en PDF-X", "Save PDF to Aperture", "Save PDF to folder as JPEG", "Save PDF to folder as TIFF", "Enregistrer le document PDF vers iPhoto", "Enregistrer sur iCloud Drive", "Enregistrer avec les reçus web", "Envoyer via Mail", "Envoyer via Messages", "Copie de AbracadabraPDF-web.qfilter", missing value, "Modifier le menu…"}
click menu item 2 of menu 1 of menu button "PDF" of sheet 1 of window 1 of process "Safari"
--> menu item "Enregistrer au format PDF" of menu "PDF" of menu button "PDF" of sheet 1 of window "MacScripter / Save Web Pages as PDF's" of application process "Safari"
keystroke "g" using {shift down, command down}
exists sheet 1 of sheet 1 of window 1 of process "Safari"
--> true
exists sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari"
--> true
get class of every UI element of sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari"
--> {static text, combo box, button, button}
get name of every button of sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari"
--> {"Aller", "Annuler"}
set value of combo box 1 of sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari" to "/Users/**********/Desktop/"
click button 1 of sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari"
--> button "Aller" of sheet 1 of sheet 1 of sheet 1 of window "MacScripter / Save Web Pages as PDF's" of application process "Safari"
exists sheet 1 of sheet 1 of sheet 1 of window 1 of process "Safari"
--> false
get class of every UI element of sheet 1 of sheet 1 of window 1 of process "Safari"
--> {static text, text field, UI element, static text, text field, group, radio group, group, pop up button, text field, splitter group, text field, static text, button, text field, static text, text field, static text, static text, text field, button, button, button}
get name of every text field of sheet 1 of sheet 1 of window 1 of process "Safari"
--> {"Enregistrer sous :", "Tags :", missing value, missing value, missing value, missing value, missing value}
set value of text field 1 of sheet 1 of sheet 1 of window 1 of process "Safari" to "TestResults.pdf"
get name of every button of sheet 1 of sheet 1 of window 1 of process "Safari"
--> {"Options de sécurité…", "Nouveau dossier", "Annuler", "Enregistrer"}
get name of last button of sheet 1 of sheet 1 of window 1 of process "Safari"
--> "Enregistrer"
click last button of sheet 1 of sheet 1 of window 1 of process "Safari"
--> button "Enregistrer" of sheet 1 of sheet 1 of window "MacScripter / Save Web Pages as PDF's" of application process "Safari"
end tell
Résultat :
button "Enregistrer" of sheet 1 of sheet 1 of window "MacScripter / Save Web Pages as PDF's" of application process "Safari" of application "System Events"
You are supposed to get something resembling to this history.
It would be fair to post here what you get on your side.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 13 janvier 2020 14:35:46