I am trying to make a windowed application appear at the loginwindow on OSX 10.11, specifically at logout.
I am calling it using a logouthook script - I can see that the app is called on logout and the delay I have added to the application pauses the logout for 10 seconds but it isn't visible.
The main window does display if triggered with a loginhook and I have tested removing the "canBecomeVisibleWithoutLogin" parameter which causes me to see errors in the system.log relating to the window not having permission to run over the loginwindow.Based on this, I believe the parameter is at least recognised.
I have looked around for examples on the web that use "canBecomeVisibleWithoutLogin" and I haven't been able to determine what step I am missing.
The code below is the only code I have added to the application which consists of a MainMenu.nib and a AppDelegate.swift.
I have also selected "visible at launch" and "Move to Active Space" in Xcode but this hasn't changed the behaviour at logout.
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate{
@IBOutlet weak var window: NSWindow!
func applicationWillFinishLaunching(notification: NSNotification) {
self.window.canBecomeVisibleWithoutLogin = true
self.window.orderFrontRegardless()
self.window.level = Int(CGWindowLevelForKey(CGWindowLevelKey.StatusWindowLevelKey))
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.window.display()
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 10 * Int64(NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {
NSApplication.sharedApplication().terminate(self)
}
}
func applicationWillTerminate(aNotification: NSNotification) {
}
}
Thanks Eskimo. I was able to get it working as I need by changing the window level manually so the app appears over the logout window. I will investigate the other options you suggest for future development. Here is my working code. Btw, I put the post in the swift forum because I was looking for a solution written in swift.
Import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
func applicationWillFinishLaunching(notification: NSNotification) {
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.window.level=2147483631
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 10 * Int64(NSEC_PER_SE
dispatch_after(time, dispatch_get_main_queue()) {
NSApplication.sharedApplication().terminate(self)
}
}
func applicationWillTerminate(aNotification: NSNotification) {
}
}