When I start an app with subprocess.Popen on Mac OS X, it starts in the background and you have to click the icon in the dock to bring it to the front. How can I make it start in the foreground?
I have tried using "open", but that creates and unwanted terminal window.
Note: the app is being started from a GUI app written using wxPython.
I think you will need to use the native API and some python bindings.
NSRunningApplication and it's method activateWithOptions is what you need. Here is an example how to use it: How to launch application and bring it to front using Cocoa api?
Look at PyObjC for bindings.
from Foundation import *
from Cocoa import *
import objc
pid = 1456
x = NSRunningApplication.runningApplicationWithProcessIdentifier_(pid)
x.activateWithOptions_(NSApplicationActivateAllWindows)
Update:
The following line is more aggressive in activating the app.
x.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
Also you might need to .unhide()
the app first.
x.hide()
x.unhide()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With