P A N
P A N

Reputation: 5922

Python in OS X: Detect multiple monitors and move application window to specific monitor

Question: Is there a way to have Python detect when running the code in OS X, if there is more than one monitor active? Is it then, possible to move a specific OS X application window to one of those monitors by choosing?


FYI: I have previously been able to utilize Carbon to activate a specific application window as seen in the code below. I'm not aware if it has the capabilities sought above.

from Carbon import AppleEvents
from Carbon import AE

window_target = AE.AECreateDesc(AppleEvents.typeApplicationBundleID, "org.mozilla.FireFox")
window_activate = AE.AECreateAppleEvent('misc', 'actv', window_target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)
window_activate.AESend(AppleEvents.kAEWaitReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

Upvotes: 1

Views: 1365

Answers (1)

Jomel Imperio
Jomel Imperio

Reputation: 934

To detect monitors, you can use NSScreen.screens(). You can then probably just position your NSWindow within the destination NSScreen's visibleFrame.

At least that would work with your own application windows -- I'm not sure about how to move a different application's window(s) or if it's even possible via the Cocoa API.

For that particular use case, one possible approach is to use AppleScript instead (e.g., Moving finder window from one display to another or Positioning a window with AppleScript using dual monitors).

Upvotes: 2

Related Questions