简体   繁体   中英

distinguish between different instances or windows of a process and find their PID instead of their owner PID to send input event in macOS?

If I open multiple windows/tabs of a browser, and I want to distinguish between them so that I can control those windows individually from my application, what is the approach? If I send command programmatically to a process with PID id it will send that command to the most recently active window but I want to send command to all the window of that process. If I query for PID of running process with CGWindowListOption I get owner PIDs of running processes. let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))

I need to know and use something that will trigger multiple window/process at the same time. Is there a different PID of different window of the same process? For example: Chrome tab 1 has a pid, tab 2 will have another pid. How to find those PIDs instead of the owner PID only?

So how can I find out different process id or similar attribute of a process with multiple window with same owner PID?

This activates each window in TextEdit and sends a space keystroke.

activate application "TextEdit"

tell application "System Events"
    tell application process "TextEdit"
        repeat with theWindow in windows
            perform action "AXRaise" of theWindow
            keystroke " "
        end repeat
    end tell
end tell

But to note how this would work without pressing keys, the following appends "A" to all the currently open documents without bringing anything to the foreground or interfering with the user's input.

tell application "TextEdit"
    repeat with theDocument in documents
        set text of theDocument to (text of theDocument) & "A"
    end repeat
end tell

Whenever possible, you want things like this rather than sending keystrokes.

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