Keyboard shortcut solution for Mac users
The Download Bar has been my #1 complaint about Google Chrome ever since I started using it, and was often a reason to switch back to Safari as my main browser. Every now and then I go through all the Google Groups topics about this, but even though there've been bug reports and feature requests about this for years, nobody at Google can be bothered to add a simple "Close Download Bar" keyboard shortcut or a "Don't show the Download Bar" checkbox in the settings.
Furthermore, the Download Bar isn't added within the window, the window is resized and then the Download Bar gets added. Hello Google, this isn't 1995 where JavaScripts are constantly resizing your application windows. I am the user, and I decide how large my windows should be.
When you close the Downloar Bar right away, the window size is restored though. However, when you interact with other applications for a while and then return to Google Chrome to close the Download Bar, it forgot the original window size for some reason, and you're stuck with the resized window. This probably isn't a problem on a screen with a high resolution, but on laptops where you have less screen real estate, it can be really annoying.
Because of the resizing, I started looking into finding a solution using AppleScript. And while I was working on that, I found a way to automate the closing of the Download Bar as well.
AppleScript that closes the Download Bar
Here's what it does:
- Opens the Downloads window (which automatically removes the Download Bar)
- Closes the Downloads window
- Returns to the previously active tab
- Optional: resizes the window to your preferred dimensions
on run
tell application "Google Chrome"
activate
-- know which tab to return to
set active_tab to active tab index of front window
tell application "System Events"
tell application process "Google Chrome"
-- opens download window and removes the download bar
keystroke "j" using {command down, shift down}
-- make sure the keystroke works
delay 0.2
-- closes the download window
keystroke "w" using command down
end tell
end tell
-- return to the tab
set active tab index of front window to active_tab
-- optional: resize to your preferred dimensions
set bounds of front window to {50, 40, 1400, 810}
end tell
end run
Like I said, after a while Google Chrome forgets the original window size. The bounds in the script are how I prefer my browser window on my MacBook Air resolution. You can remove this, or set it to whatever you want. I guess it's also possible to determine what the bounds are after the window has been resized, and then calculate what they were if you subtract the height of the Download Bar.
Install AppleScript as Service with keyboard shortcut
The easiest way to run this script is to install it as a system wide Service that you can then activate using a keyboard shortcut. To do this, follow these steps:
- Start the Automator application
- Create a "Service"
- Set the "Service receives" to "no input" (drop down) at the top
- Search for "AppleScript" on the left
- Drag the "Run AppleScript" action to the Workflow pane on the right
- Paste in the above code (and test it if you like)
- Save the Service as something like "Google Chrome: Close Download Bar"
Next:
- Go to System Preferences > Keyboard
- Select "Services" on the left
- Find your newly created Service on the right under the heading "General"
- Double click on the right side of that line to activate the shortcut input box
- Press your preferred key combo (I used Control–Option–Command–J)
And that's it. Now, whenever you press your key combo, Google Chrome will be activated (if it wasn't already), and the AppleScript is loaded removing the Download Bar. So it's also an easy way to quickly return to Chrome, e.g. when you did something with the file you downloaded.
Note 1: This also works in Google Chrome Canary; simply refer to "Google Chrome Canary" in the AppleScript.
Note 2: A similar approach should work in Windows using AutoHotKey.
1
Ctrl-J Ctrl-W
does exactly what you are asking. – xdavidliu – 2019-09-24T02:46:41.547