0

I have two iTerm2 windows open, and I want to place and resize one via Hammerspoon while leaving the other one as is.

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Right", function()
    local layout = {
        {"iTerm2", "/in/my/work/dir", nil, hs.geometry.rect(0.0, 0.40, 0.6, 0.6), nil, nil},
    }
    hs.layout.apply(layout)
end)

When I run the code as above, nothing happens; Hammerspoon does not find my iTerm2 windows, even though it looks like my window has "/in/my/work/dir" in the title.

When I replace "/in/my/work/dir" with nil, Hammerspoon moves and resizes all my iTerm2 windows. This makes sense, since I just ask for all iTerm2 windows without specifying a title.

When I add debug code to print the list of my iTerm2 windows to the console, I see only one iTerm2 window:

hs.fnutils.each(hs.application.runningApplications(), function(app)
    if string.find(app:name(), "iTerm2") then
         print("Found " .. app:name() .. " -- " .. app:title())
    end
end)

This prints:

Found iTerm2 -- iTerm2

How can I use Hammerspoon to tell my iTerm2 windows apart and move / resize only one of them?

Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

0

This actually works when you pass the complete title, not only a part of the title. I guess I got misled when the documentation said "string containing a window title". It has to be an exact match.

Robert
  • 7,394
  • 40
  • 45
  • 64
  • 1
    I can confirm this in 2022: for iTerm2, one needs to specify the exact matching window name; a regexp (as documented in hammerspoon) does not work. Interestingly, when outputting the windows which hammerspoon sees (hs.window.list()), the iTerm2 windows are in there, but there windowName property is missing. Not even nil, but the property is not there. In fact, the same seems to be true for many other of my apps (but not all - for some, the windowName is there). – AnoE Nov 02 '22 at 10:04