A shortcut for Merge all Windows on macOS Sierra

Are there any shortcut for the command merge all windows feature that comes with macOS Sierra? I did not encounter about an shortcut for this command and I did not see any property in Automator app. If is it possible, it will be nice improvement for productivity when we working with tabs rather than windows.


Solution 1:

  1. Open System PreferencesKeyboardShortcutsApp Shortcuts.
  2. Click the + to add a new shortcut.
  3. Choose All Applications from the Application dropdown.
  4. As the Menu Title, enter Merge All Windows (*see note at the bottom).
  5. Input a key combination of your choice as the Keyboard Shortcut. I use Ctrl ^W.

Now all applications with a menu item called Merge All Windows will respond to that key combination, and collapse all your windows into one.

Starting with Sierra, it is also possible to open documents in new tabs rather than in new windows. This is enabled by going into System PreferencesDock and setting Prefer tabs when opening documents to Always.

If you would like new Terminal sessions to open as new tabs as well, you can achieve this by placing a file named .bashrc in ~ (your Home folder), with the following line in it:

osascript -e 'tell application "System Events" to click menu item "Merge All Windows" of menu "Window" of menu bar 1 of process "Terminal"' >/dev/null 2>&1

Note: Merge All Windows may differ based on your operating system's language. If you are not using the English (US) locale, open Finder, and click the Window menu to determine the name of that command in your locale.

Solution 2:

This one works for me just fine for Safari and Finder:

tell application "Safari"
    activate
    tell application "System Events"
        tell process "Safari"
            click menu item "Merge All Windows" of menu "Window" of menu bar 1
        end tell
    end tell
end tell

Let me know if this solves your issue.

edit: This script works for any active app that supports "Merge all windows":

try
    tell application "System Events" to tell (first process where it is frontmost) to click menu item "Merge All Windows" of menu "Window" of menu bar 1
end try