Saving Safari downloads to specified folder

Hi I’m pretty new to scripting - have only made one script that worked before but I did get help from here with that too so now I’ve signed up.

Here’s my problem:
I want Safari to save all files that I download in a specific folder withing the download-folder. The specific folder should have the date of the day as title. I thought of it and come up with that I probably can’t make Safari do all the work so I have so far come up with a script (which is a work in progress) that should create a folder when I login and set todays date as the title of that folder. Next step is to “convince” Safari to save the files that I download one day in the folder whos title corresponds with the date of the download. Anyone get that…?

I’ve come this far:

For a start, there’s a much easier way of creating a folder without going through the pain of using UI scripting (selecting menus, typing, etc., etc., etc):

set downloadsFolder to ((path to shared documents) as text) & "Download:"
set newFolderName to date of today(yyyymmdd)
tell application "Finder"
    set newFolder to make new folder at folder downloadsFolder with properties {name:newFolderName}
end tell

(note, this presumes you already have a ‘today’ handler to handle the date conversion)

This script uses the ‘path to’ command to find the Shared folder (so the script is portable and will still work even if you change disk names, etc.) and it works silently, without having to open windows, etc.

As for the Safari part, I’m not entirely sure but it looks to me like Safari saves the downloads folder in it’s preference file as ‘NSNavLastCurrentDirectory’, so you can use the ‘defaults’ command to change this setting before launching Safari:

do shell script "defaults write com.apple.Safari NSNavLastCurrentDirectory " & quoted form of POSIX path of newFolder

This script automatically converts the path of the newly-created folder to posix (unix) style which is then passed into the defaults command to update Safari’s preferences.

What you should do is create a folder action script attached to your downloads folder. When new files are added, it checks for a folder with today’s date in some default location. If the folder is not found, create it. Finally, add a loop to the script to make sure the files being downloaded via Safari are complete before they are moved and then move them to today’s folder (search the board for Safari download wait scripts).

Jon

Well thankyou both.
Those tips are really helpful to me. Now I just have to put it together and make it work - I’ll be back with the results…

There’s just one thing. I don’t think I have to set the download folder everytime the script is run because thats already set in Safaris prefs