applescript: merge windows in finder

The finder dictionary for Applescript doesn't have an event for merging windows. So, I assume something similar as what you see here isn't possible.


tell application "Finder"

activate

merging(merge all windows)

tell every window to merging

end tell


Is there any workaround?

Posted on Jun 28, 2017 2:59 AM

Reply
9 replies

Jun 28, 2017 6:21 AM in response to pereelmagne

No AppleScript needed.


  1. Launch System Preferences : Keyboard panel : Shortcuts : App Shortcuts
  2. Click the [ + ] button to add a new App Shortcut
    1. Application: Finder
    2. Menu Title: Merge All Windows
    3. Keyboard Shortcut: ctrl+shift+W (didn't appear to conflict with existing shortcuts)
    4. Click Add
  3. Quit System Preferences panel
    User uploaded file

Open two Finder Windows, then ctrl+shift+W. Both windows will merge to one, and in my case as tabs.

Jun 28, 2017 3:32 AM in response to pereelmagne

You can probably do it with GUI scripting, but telling System Events to click on the specific menu.

One easier way is to add a keyboard shortcut to the Merge All Windows command, and then then just tell System Events to press the shortcut.


Here is how that last one would work.


1) Add a shortcut to "Merge All Windows" (in this example, Command-Option-M; adjust accordingly if you choose a different shortcut):


User uploaded file


2) Do the Applescript this way:


tell application "Finder"

activate

end tell

tell application "System Events"

keystroke "m" using {command down, option down}

end tell

Jun 29, 2017 1:25 AM in response to Luis Sequeira1

m - command - option is minimize all windows so either you will get a conflict or more likely you will lose that facility - you could choose a keystroke which doesn't conflict with an existing one. This script will do it without having to set a keystroke (though that's a useful option by itself):


tell application "System Events"

tell process "Finder"

click menu item "Merge All Windows" of menu "Window" of menu bar 1

end tell

end tell

Jun 28, 2017 3:28 AM in response to pereelmagne

Start by creating a folder (in this example called "New folder" on the Desktop. Then open all the folders whose contents you want to move to New Folder. Then run this script (replacing 'xxxx' with the name of your Home Folder, of course):


tell application "Finder"

move every item of (every window whose visible is true) to folder "New folder" of folder "Desktop" of folder "xxxx" of folder "Users" of startup disk

end tell


(Note that there are only three lines here, the forum display may break line 2). You can of course call the new folder anything, and place it anywhere you like provided you amend the script to show the path.


This script will move the files, leaving the original folders empty. You may prefer to copy the files, so that they remain in position as well as appearing in the new folder, just as a safety precaution. Then you can delete the original folders if you wish.


tell application "Finder"

copy every item of (every window whose visible is true) to folder "New folder" of folder "Desktop" of folder "xxxx" of folder "Users" of startup disk

end tell

Jun 28, 2017 3:59 AM in response to Roger Wilmut1

Roger Wilmut1 wrote:


m - command - option is minimize all windows so either you will get a conflict or more likely you will lose that facility. This script will do it without setting a keystroke (though that's a useful option by itself):


tell application "System Events"

tell process "Finder"

click menu item "Merge All Windows" of menu "Window" of menu bar 1

end tell

end tell


Good call - I just picked a shortcut as an example, and did not take the time to check

Your solution is the right one. I knew it is was something like that but I know the "keystroke" command by rote...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

applescript: merge windows in finder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.