-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
previous window screen name #1424
Comments
Does something like this work: appWatcher = hs.application.watcher.new(function(name, event, app)
if event == hs.application.watcher.deactivated then
if app then
local focusedWindow = app:focusedWindow()
if focusedWindow then
local screen = focusedWindow:screen()
if screen then
print(app:name(), focusedWindow:title(), screen:name())
else
print("unable to get screen for " .. tostring(focusedWindow:title()))
end
else
print("unable to get focusedWindow for " .. tostring(app:name()))
end
else
print("no application object returned for " .. tostring(name))
end
end
end):start() I don't have multiple monitors available to me atm, but a quick testing looks like it's working on my machine... a few "headless" applications (i.e. no dock icon) seem to give it trouble with "no focused window for ..." but depending upon your usage this might be sufficient or you could try checking out |
@asmagill thanks so much, works like a charm! I need to move mouse cursor from another screen every time I switch windows, in the meantime I got it working in different way - simply checking whether mouse pointer is located on another screen or not: function applicationWatcher(appName, eventType, appObject)
if (eventType == hs.application.watcher.activated) then
local win = hs.window.focusedWindow()
-- move mouse pointer if it is located on different screen
if (win:screen():id() ~= hs.mouse.getCurrentScreen():id()) then
local f = win:frame()
center_x = f.x + f.w/2 + f.w * 0.2
center_y = f.y + f.h/2 + f.h * 0.2
hs.mouse.setAbsolutePosition(hs.geometry.point(center_x, center_y))
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start() |
Hello,
would it be possible to obtain a screen name of the previous application window?
I tried to grab the window and screen in hs.application.watcher.deactivated but it does not seem to work.
Thanks
The text was updated successfully, but these errors were encountered: