Change Safari Download Folder issue

I have a routine that changes the default download location in Safari.

My issue is that the first time I try and download after running the script that changes it a window appears that asks me to “confirm your file download location” . As this is part of an automaton script I don’t want to have to confirm. In testing (when I have not reset the downloads to the default folder ) it does not ask again.

The window I referred to looks like a finder window the header caption is as I described and at the bottom I have open and cancel buttons. What I need to do is programmatically hit the open button.

The script below changes the folder

on SetDownLoadFolder()
set Thefolder to alias “Macintosh HD:Users:petermitchell:Dropbox:”
set Dfolder to quoted form of POSIX path of Thefolder
tell application “Safari” to quit – Ensure Safari quit’s using repeat loop
tell application “System Events” – One delay makes the script stable
repeat while application process “Safari” exists
delay 0.1
end repeat
end tell
do shell script ("defaults write DownloadsPath " & Dfolder) --Change Default
tell application “Safari” to activate
end SetDownLoadFolder

Sorry once again not thinking properly the window is not of course from finder but Safari. Once I figured that out easy enough to issue the correct command.

Juts in case anyone is as thick as I.

tell application “System Events”
tell process “Safari”
click button “Open” of window “Open”
end tell
end tell