Skip to content

Instantly share code, notes, and snippets.

@selfire1
Last active March 20, 2022 10:56
Show Gist options
  • Save selfire1/b2e004c19d7c91dee1516895571696d2 to your computer and use it in GitHub Desktop.
Save selfire1/b2e004c19d7c91dee1516895571696d2 to your computer and use it in GitHub Desktop.
An Applescript to resize windows from the command line
on run argv
-- Variables
set _cmd to (item 1 of argv)
tell application "Finder" to set _bounds to bounds of window of desktop
set _xPos to (item 1 of _bounds)
set _yPos to (item 2 of _bounds)
set _ySize to (item 3 of _bounds)
set _xSize to (item 4 of _bounds)
-- get bounds
-- do split: app1, app2, set split
if (_cmd = "split") then
set _app1 to (item 2 of argv)
set _app2 to (item 3 of argv)
set _splitPerc to ((item 4 of argv)/100)
set _splitPoint to (_ySize*_splitPerc)
tell application "System Events" to tell process _app1
set position of front window to {_xPos, _yPos}
set size of front window to {_splitPoint, _xSize}
end tell
tell application "System Events" to tell process _app2
set position of front window to {_splitPoint, _yPos}
set size of front window to {_ySize-_splitPoint, _xSize}
end tell
if (_splitPerc >= 0.5) then
--your code
tell application _app2 to activate
tell application _app1 to activate
else
--your code
tell application _app1 to activate
tell application _app2 to activate
end if
end if
end run
@selfire1
Copy link
Author

Example usage from the command line:
osascript resize.scpt split "Brave Browser" "Obsidian" 70

  • osascript resize.scpt – Run the script as an Applescript
  • split – Command function (I might add more in the future)
  • "Brave Browser" – Application to place on the left side
  • "Obsidian" – Application to place on the right side
  • 70 – Percentage of the application on the right

Result: Brave Browser gets fills the left 70% of the screen, Obsidian the right 30%.

I like to use this with Bunch App for window placement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment