A script to close Safari's Downloads window

From the pages os Mac OS X Hints.com get the most from X! http://www.macosxhints.com

Here’s a simple script to tell Safari’s downloads window to close.

Like I said, it’s simple. :slight_smile: 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.

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.

OS version:

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