Skip to content

Instantly share code, notes, and snippets.

@fiedl
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiedl/21a401f56e895412960c to your computer and use it in GitHub Desktop.
Save fiedl/21a401f56e895412960c to your computer and use it in GitHub Desktop.
Mac OS Window Management: Snap windows 2/3 of the screen when pressing Shift_R.
<?xml version="1.0"?>
<root>
<item>
<name>Change Shift_R to F18</name>
<identifier>private.change_shift_r_to_f18</identifier>
<autogen>
__KeyToKey__
KeyCode::SHIFT_R,
KeyCode::F18
</autogen>
</item>
</root>
set activeApp to (path to frontmost application as Unicode text)
-- Screen Resolution
tell application "Finder"
set screenResolution to bounds of window of desktop
end tell
set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution
if (screenWidth > 2500) then
set numberOfPresets to 5
else
set numberOfPresets to 4
end if
if (screenWidth > 2560) then
-- dual monitor. just use the large one.
set screenWidth to 2560
set numberOfPresets to 5
end if
-- position preset counter
property positionPreset : 0
set positionPreset to positionPreset + 1
if positionPreset > numberOfPresets
set positionPreset to 1
end if
tell application activeApp
-- Window Position
set current_position to the bounds of the first window
set current_xposition to item 1 of current_position
activate
set goldenRatio to 0.618
-- External Display Display: 2560
if screenWidth = 2560 then
-- Use 1/3 1/3 1/3 configuration.
if positionPreset is 1 then
set the bounds of the first window to {1 / 3 * screenWidth, 0, 2 / 3 * screenWidth, screenHeight}
else if positionPreset is 2 then
set the bounds of the first window to {2 / 3 * screenWidth, 0, 3 / 3 * screenWidth, screenHeight}
else if positionPreset is 3 then
set the bounds of the first window to {0 / 3 * screenWidth, 0, 1 / 3 * screenWidth, screenHeight}
else if positionPreset is 4 then
set the bounds of the first window to {goldenRatio * screenWidth, 0, screenWidth, screenHeight}
else if positionPreset is 5 then
set the bounds of the first window to {0, 0, goldenRatio * screenWidth, screenHeight}
end if
-- Retina 15 inch display
else
if positionPreset is 1 then
set the bounds of the first window to {goldenRatio * screenWidth, 0, screenWidth, screenHeight}
else if positionPreset is 2 then
set the bounds of the first window to {0, 0, goldenRatio * screenWidth, screenHeight}
else if positionPreset is 3 then
set the bounds of the first window to {screenWidth / 2, 0, screenWidth, screenHeight}
else if positionPreset is 4 then
set the bounds of the first window to {0, 0, screenWidth / 2, screenHeight}
end if
end if
end tell
  • Use Karabiner to route the right shift key to another key, e.g. F18.
  • Use Apple Script in Spark or another hotkey manager to resize the window.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment