property workInProgress : true
set_download_folder("~")
on set_download_folder(dlFolder)
activate application "Safari"
tell application "System Events" to tell application process "Safari"
click menu item 6 of menu 1 of menu bar item "Safari" of menu bar 1 (* Preferences… *)
tell tool bar 1 of window 1
if workInProgress then
name of every button
--> {"Général", "Aspect", "Signets", "Onglets", "RSS", "Rempl. auto.", "Sécurité", "Extensions", "Avancées"}
end if
set General_loc to name of first button
click button General_loc
end tell
if workInProgress then
tell group 1 of group 1 of window General_loc
class of UI elements
--> {static text, text field, checkbox, static text, pop up button, static text, static text, pop up button, static text, pop up button, pop up button, button, static text, static text, pop up button, button, static text, pop up button, pop up button, static text}
name of every pop up button
--> {"Les nouvelles fenêtres s’ouvrent avec :", "Navigateur web par défaut :", "Moteur de recherche par défaut :", "Enregistrer les fichiers téléchargés sur :", "Effacer la liste des téléchargements :", "Supprimer les éléments de l’historique :", "Les nouveaux onglets s’ouvrent avec :"}
end tell
end if
tell pop up button 4 of group 1 of group 1 of window General_loc
click
if workInProgress then
name of every menu item of menu 1
--> {"Documents", missing value, "Autre emplacement…"}
end if
click menu item 3 of menu 1 (* reveal the sheet allowing us to select the Download folder *)
end tell
if workInProgress then
--When it's a work in progress, I use this code which exit if the sheet doesn't appear
repeat 10 times
if exists sheet 1 of window General_loc then
set sheet_available to true
exit repeat
end if
delay 0.2
set sheet_available to false
end repeat
if not sheet_available then error number -128
else
repeat until exists sheet 1 of window General_loc
delay 0.1
end repeat
end if
if workInProgress then
tell sheet 1 of window General_loc
class of UI elements
--> {button, button, button, group, grow area}
name of every button
--> {"Sélectionner", "Nouveau dossier", "Annuler"}
end tell
end if
keystroke "g" using {shift down, command down}
repeat until exists sheet 1 of sheet 1 of window General_loc
delay 0.1
end repeat
tell sheet 1 of sheet 1 of window General_loc
if workInProgress then
class of UI elements
--> {static text, text field, button, button, static text, grow area}
name of every button
--> {"Aller", "Annuler"}
end if
set value of text field 1 to dlFolder
click button 1
end tell
click button 1 of sheet 1 of window General_loc
click button 1 of window General_loc
end tell
end set_download_folder