Reputation: 37288
I am trying to focus all windows of another process, I know the PID of it.
When I run the following code:
app = [NSRuningApplication runningApplicationWithProcessIdentifier: 400];
[app activateWithOptions: (NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]
All windows that are NOT minimized/miniaturized are shown. HOWEVER if all of the windows are minimized/miniaturized none of the windows are shown.
How can I un-minimize all windows on activate? I also tried SetFrontProcess
but that had the exact same issue.
Here is a screen-cast I made of the issue: https://www.youtube.com/watch?v=sR5uf4eR8js
I found one whacky semi-solution, which was to run killall Dock
, this un-minimizes all minimized windows however. I just need to un-minimize windows of a specific PID.
Upvotes: 0
Views: 312
Reputation: 90641
First, just to be clear, -activateWithOptions:
is activating the other instance of Firefox. You can tell by, for example, looking at its Window menu. The only issue is that it hasn't unminimized any windows. That's not necessarily incorrect behavior. For example, if you use Command-Tab to switch to the other Firefox, instead of clicking on its Dock icon, it would become active but would not unminimize its window.
So, you should consider maybe just leaving it how it is.
If you really want to change it, though, try doing the following instead of -activateWithOptions:
:
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:app.bundleURL
options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchWithoutAddingToRecents
configuration:@{}
error:NULL];
That's approximately equivalent to clicking on the app's Dock icon. Or opening the app from the Finder. Since it's already running, the existing instance will be activated and sent the reopen application
(kAEReopenApplication
a.k.a. 'rapp'
) Apple event. The standard behavior will unminimize a window if all of its windows are minimized. (If it has no open windows, it will typically create a new, default window. In a document editor, this would be a new, untitled document. In Firefox, this would be the home page.)
This will not unminimize all windows, but that's generally not desired, anyway.
Upvotes: 1