change "save downloaded file to" preference script

Hi,

I am too new to be of any help … I just hope someone can help me … I wish to make a script that would change in the preferences of safari the “save downloaded file to” to a folder that is on my desktop called “here”… I need to automatise tricky processes and I would have to change this preference several times automatically. I would need to know how to do it once. It would really help me a lot ! How can I do that ?? Is it even possible ? sounds really really hard to me :rolleyes:!

thanks for any help on this one !!!

you would have to script it using UI elements and I’m not sure how well that would work for you it may be a little easier if you used Firefox but I’m not sure …I"ll play around with it but I cant promise anything

For this to work you need to make sure “enable access for assistive devices” is checked in the Universal Access preference pane. It uses UI scripting, so it may not work perfectly for you, but give it a try.


set dlFolder to "~/Desktop/here"
my set_download_folder(dlFolder)

on set_download_folder(dlFolder)
	activate application "Safari"
	tell application "System Events" to tell application process "Safari"
		click menu item "Preferences." of menu 1 of menu bar item "Safari" of menu bar 1
		click button "General" of tool bar 1 of window 1
		tell pop up button 3 of group 1 of group 1 of window "General"
			click
			click menu item "Other." of menu 1
		end tell
		
		keystroke "g" using {shift down, command down}
		delay 2 -- This value should be increased if the new download location doesn't appear in the Go To Folder dialog
		
		tell window "Go To Folder"
			set value of text field 1 to dlFolder
			click button "Go"
		end tell
		click button "Select" of sheet 1 of window "General"
		click button 1 of window "General"
	end tell
end set_download_folder