From e826cb04b8d827275a81cc8371e5217ca8a2fb4f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 26 Jul 2019 22:07:38 +0200 Subject: window_layout: Fix iTerm window #2 targeting Using an index of 2 didn't guarantee that the window accessed would be window #2. Turns out the order of windows in the list is not consistent. In order to target window #2, look for the "2. " prefix in the window title. --- window_layout.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'window_layout.lua') diff --git a/window_layout.lua b/window_layout.lua index 1b6a8b1..263bc89 100644 --- a/window_layout.lua +++ b/window_layout.lua @@ -2,10 +2,12 @@ -- https://www.hammerspoon.org/docs/hs.screen.watcher.html -- hs.screen.primaryScreen():name() == 'G247HL' local function iterm2() - -- TODO: Use `filter()` to get windows with title starting with "2. ". This - -- code grabbed window 3 once. - local win_2 = hs.application.find('com.googlecode.iterm2'):allWindows()[2] - win_2:setFrame(hs.geometry.rect(-1253.0,23.0,793.0,873.0)) + for _, window in ipairs(hs.application.find('com.googlecode.iterm2'):allWindows()) do + if window:title():match('^2%. ') then + window:setFrame(hs.geometry.rect(-1253.0,23.0,793.0,873.0)) + return + end + end end -- cgit v1.2.3