Fix type_into_keyboard on OS X. When the application is in the background, NSApplication has a nil -mainWindow.