Window does not get active when shown from command line tool

Hello,

I am making a LaunchAgent that shows a NSAlert modal when the user makes a specific action.

I need this NSAlert to be active when appearing on the user screen (i.e. all other windows need to be in a non-active state).

However, the NSAlert does not get active and the window just under it stays active.

When the NSAlert is shown from a basic Storyboard based app, the NSAlert gets active.

So I use eskimo's tutorial to transfer my LaunchAgent to an app bundle and now the NSAlert becomes active when appearing!

Moving the binary from Contents/MacOS and launching it outside of the bundle make the NSAlert inactive again.

Now my question is, is this behavior documented somewhere? Why do we need the binary to be in a app bundle for it to be able to have active window?

Thank you!

Hi! Does your binary make itself the active application before displaying the NSAlert? Adding a NSApplication.shared.activate(ignoringOtherApps: true) before showing the NSAlert might do the trick.

Hi!

Thanks for your suggestion. The binary already makes itself the active application with NSApp.activate(ignoringOtherApps: true) but it had no effect.

Moving a binary out of its app bundle makes its window non-active so I think there something related to app bundle...

As a side note, talking about bundle, the Info.plist has Application is agent (UIElement).

Window does not get active when shown from command line tool
 
 
Q