开发者

Python appscript OSAX display_dialog: how to move it to foreground

开发者 https://www.devze.com 2023-03-28 09:55 出处:网络
I am playing around with the example from here; esp. I have this code: from osax import * sa = OSAX() print sa.display_dialog(\"Python says hello!\",

I am playing around with the example from here; esp. I have this code:

from osax import *

sa = OSAX()

print sa.display_dialog("Python says hello!",
                        buttons=["Hi!", "Howdy!", "Duuuude!"],
                        default_开发者_C百科button=3)

The dialog always opens in the background. How can I open it in (or move it to) the foreground?


Add an activate command to give your Python process the window manager application focus.

sa = OSAX()
sa.activate()
print sa.display_dialog(...)

You can also choose to not GUIfy your Python process by targeting a faceless background app as described here.


This works for now:

def go_foreground():
    from AppKit import NSApp, NSApplication
    NSApplication.sharedApplication()
    NSApp().activateIgnoringOtherApps_(True)
go_foreground()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号