Jul 16, '04 10:07:00AM • Contributed by: pascalpp
Like I said, it's simple. :) The on error bit ensures that it's the actual Downloads window, not a browser window viewing a page with the title "Downloads," that's being closed.
tell application "Safari" repeat with w in windows if name of w is "Downloads" then set isdocument to true try set d to document of w set the result to d on error set isdocument to false end try if (not isdocument) then tell w to close end if end if end repeat end tell
If you're running Quickeys or some other automation utility, you can set this script to fire every 5 or 10 minutes. If you don't have Quickeys, you could also fire this script at a given interval using osascript and cron -- see other hints for more on how to do that.
Unfortunately there doesn't seem to be a way to check if anything's currently downloading before closing, but for me that's not a problem as I rarely use Safari to download things that take longer than five minutes.