Last active
January 18, 2021 11:47
-
-
Save henckellbach/a95153da6390b7f4e285958a743df9ad to your computer and use it in GitHub Desktop.
AppleScript application for organizing your open windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- You need to allow assistive access to this application | |
| -- System Preferences > Security > Privacy > Privacy > Accessibility | |
| -- AppleScript does not allow optional parameters, therefore we are using a list of parameters | |
| -- @param {string} processName - Name of the application process | |
| -- @param {int} x - Window X position | |
| -- @param {int} y - Window Y position | |
| -- @param {int} w - Window width | |
| -- @param {int} h - Window height | |
| -- @param {int} xOffsetDirection - Additional windows offset direction (-1 for left, 1 for right) | |
| on resizeApp(params) | |
| set processName to item 1 of params | |
| set x to item 2 of params | |
| set y to item 3 of params | |
| set w to item 4 of params | |
| set h to item 5 of params | |
| -- Effectively make the last item optional | |
| if (count params) = 6 then | |
| set xOffsetDirection to item 6 of params | |
| else | |
| set xOffsetDirection to 1 | |
| end if | |
| tell application "System Events" | |
| tell process processName | |
| set windowList to every window | |
| set i to 0 | |
| repeat with currentWindow in windowList | |
| try | |
| set xOffset to (i * 40 * xOffsetDirection) | |
| set position of currentWindow to {x + xOffset, y} | |
| set size of currentWindow to {w, h} | |
| set i to (i + 1) | |
| on error errormsg | |
| display dialog "An error has occured. | |
| " & errormsg with title "Error" buttons {"OK"} | |
| end try | |
| end repeat | |
| end tell | |
| end tell | |
| end resizeApp | |
| -- If you rock a multi-monitor setup, you might need to use negative x and y positions to move windows to secondary screens | |
| on run {input, parameters} | |
| resizeApp({"Terminal", -1920, 660, 620, 380}) | |
| resizeApp({"Fork", -1920, 0, 1056, 659}) | |
| resizeApp({"Code", -1520, 0, 1520, 1000, -1}) | |
| end run |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to Use
An application will be just a regular application which you can launch from Finder, your desktop or the dock.
A Quick Action can be launched from the menu bar (under Services) or even from the Touch Bar.
You might need to play around with the values a little bit, based on your system. Multi-monitor setups might even need negative x values. I recommend updating the arguments one by one going from the left until you are satisfied with the results.
Adding the Quick Action to your Touch Bar