Four Steps To Write An OSX AppleScript to Gather ALL Windows

Four Steps To Write An AppleScript to Gather ALL Windows on OSX

I have no idea why, but there is no built-in way to gather ALL your desktop windows (from all applications) onto your main display window. There are some apps out there that will do it for each individual application but nothing that I've been able to find that will do it for all windows from all applications at once.

Example of gathering all windows

And it doesn't look like I'm alone in wanting something like this. See all these threads out there...

Anyway, lets build a simple AppleScript that loops through all your open applications and moves all their (non-minimized) windows to a specific x,y position on your screen and (optionally) resize them.

Step #1 - Fire up the OSX Script Editor

OSX comes with its own built in AppleScript editor called "Script Editor". You can find it under Applications > Utilities.

Open OSX Script Editor
Pause reading for 5 seconds...
Join My Mailing List!
Note: I will never share your email with anyone else.
Awesome! Thanks so much.
Ok, lets continue.

Step #2 - Paste in the following AppleScript

The AppleScript below with loop through each non-minimized window of every applicaition you have open and and move it's window position to 200, 100 (top left of your screen). It will also resize each window to 1000px by 800px.

If you don't want it to resize your windows or you'd like your windows placed somewhere else you can edit the script accordingly...

use application "System Events"

get the name of every application process whose class of windows contains window

repeat with P in the result
	
	get (every window of process (contents of P) whose value of attribute "AXMinimized" is false)
	
	repeat with W in the result
		
		set position of W to {200, 100}
		set size of W to {1000, 800}
		
	end repeat
	
end repeat

Step #3 - Run the AppleScript

Click the play button in the top left corner to fire off the script...

Pasted AppleScript Code

And after a couple seconds you will hopefully see all your open windows from all your open displays moving up to the top left corner of your screen.

Note: You might be prompted to enable your script with permissions to move windows around. This is called "assistive" permissions, and you can find them inside your Security and Privacy settings in the control panel...

Assistive Permissions

Step #4 - Save Your Script as an Application

Its all well and good to have a script in the script editor that does the window gathering you want, it's better to have that all bundled up as an application so you can run it whenever you want.

To do this, go back to your script editor and under the File dropdown menu hit "Export"...

Export your applescript

Then choose to export it as an application...

Export your applescript as an application

Now you have an .app file that you can drag onto your doc and run whenever you want to move your windows around in batch.

Hopefully this has been helpful for you. If you've tried out the code here, drop me a tweet at twitter.com/mattccrampton and let me know.