Question: I've needed to do some things on Change event of jQuery Autocomplete. It's working as I expected (doing these things after changing and losing focus). 

However, if I click on submit button or press Enter (that submits too) the Autocomplete Change event is only firing after submit's done and I need it before submitting.

I've already tried some things like trigger change event on submitting event and other palliative things but nothing worked (using Select event is not an option).

Answer: 
It also can return nil if the main app window is not active on macOS. For instance I ran into this when I was making a drag and drop file uploader. If the window was not in the front (on the operating system) it would return nil. The following line of code will activate your app (bring to front)

```
NSApp.activateIgnoringOtherApps(true)

```

I also needed a timer to delay my call of mainWindow in my case.
Make sure you have a **Window** in your storyboard as *Initial Controller*