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?
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.