简体   繁体   中英

MacOS: Determine which monitor any window application is on?

I'm currently attempting to have my system pipe audio to a specific output depending on which monitor that application is running on. For instance, if a web browser is playing videos on monitor A, sound comes out of output 1. If it is on monitor B, it comes out of output 2. Is there any way to poll which monitor any/all applications are located/active on macOS?

The question hasn't given many details, but in principle you can recover the position of the window using code like the:

tell application "System Events"
    tell process "App Name"
        set windowPos to position of first window
    end tell
end tell

... and then compare that to the frame of each desktop to discover which display the window is in. If you need to determine the frame of each desktop programmatically (instead of hand-coding them in), that will take some extra work: either digging the values out of a system plist file or using AppleScriptObjC to get the frame dimensions from NSScreen. Let me know if you need that, and I'll update when I get a chance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM