I've been looking for a simpler and faster solution. I ultimately settled on a hammerspoon script triggered with a global keyboard shortcut.
It basically does what's been described in the previous answers, just automatically, and binds the execution to ⌘ Command^ ControlF. There is also a one second delay to let the tile animation finish before executing the mouse click. This works for me, but one could probably experiment with the value. I've been searching for a way to disable this animation, but no option seems to affect this one. If anyone knows if it's possible, that'd be great.
Oh, and one more thing - the menus are localised, so you should change {"Okno", "Umieść okno po lewej stronie ekranu"}
to you own language. I believe in English it's {"Window", "Tile Window to Left of Screen"}
.
EDIT: Some apps don't have the Window
menu, so I added an alternative fallback method.
local log = hs.logger.new('fullscreen-right','debug')
local function clickOnLeftScreenSide()
log.d("left-clicking")
local mousePosition = hs.mouse.getRelativePosition()
local currentScreenFrame = hs.mouse.getCurrentScreen():frame()
hs.eventtap.leftClick(
{
x = currentScreenFrame.x + 10,
y = currentScreenFrame.y + 10
}, -- with padding
1000 -- hold for 1ms
)
-- restore the original mouse position
hs.mouse.setRelativePosition(mousePosition)
end
local delayedWindowClick = hs.timer.delayed.new(1, clickOnLeftScreenSide)
local function trySelectingMenuItem(app)
local selected = app:selectMenuItem({"Okno", "Umieść okno po lewej stronie ekranu"})
if not selected then -- fallback to english for some apps
selected = app:selectMenuItem({"Window", "Tile Window to Left of Screen"})
end
if not selected then
log.d("No such menu item")
end
return selected
end
local function tileToTheLeft(app)
local window = app:focusedWindow()
if not window then
log.d("No window found")
return false
end
local windowAx = hs.axuielement.windowElement(window)
windowAx:setTimeout(0.01)
resizeButtonAx = windowAx:attributeValue("AXFullScreenButton")
resizeButtonAx:setTimeout(0.01)
resizeButtonAx:performAction("AXShowMenu")
hs.eventtap.keyStroke({}, "down", 1000)
hs.eventtap.keyStroke({}, "down", 1000)
hs.eventtap.keyStroke({}, "return", 1000)
end
hs.hotkey.bind({"cmd", "ctrl"}, "F", function ()
local app = hs.application.frontmostApplication()
if not app then
log.d("No frontmost app found")
return
end
if not trySelectingMenuItem(app) then
-- fallback to another method if the menu is absent
tileToTheLeft(app)
end
delayedWindowClick:start()
end)