Search code examples
macosfullscreenswift2

How to set up Kiosk Mode for Mac apps?


I am trying to make the application startup in a presentation mode while disabling the Dock, Menubar, Processes Switching, etc. I have this code so far:

let presOptions: NSApplicationPresentationOptions =
        .HideDock                  |   // Dock is entirely unavailable. Spotlight menu is disabled.
    //  .AutoHideMenuBar           |   // Menu Bar appears when moused to.
    //  .DisableAppleMenu          |   // All Apple menu items are disabled.
        .DisableProcessSwitching   |   // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
        .DisableForceQuit          |   // Cmd+Opt+Esc panel is disabled.
        .DisableSessionTermination |   // PowerKey panel and Restart/Shut Down/Log Out are disabled.
        .DisableHideApplication    |   // Application "Hide" menu item is disabled.
    //  .AutoHideToolbar           |
        .FullScreen

let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: presOptions]

browserWindowController.containerView.enterFullScreenMode(NSScreen.mainScreen()!, withOptions: optionsDictionary)

On the .HideDock line I get the error:

Type of expression is ambiguous without more context

Could somebody help me find a solution for that and explain what the error means.

Also on the browserWindowController line I get the error:

Use of unresolved identifier 'browserWindowController'

Could somebody explain to me why this isn't working?


Solution

  • With Swift 2 NSApplicationPresentationOptions has to be an array:

    let presOptions: NSApplicationPresentationOptions = [
        .HideDock,                     // Dock is entirely unavailable. Spotlight menu is disabled.
        //  .AutoHideMenuBar,           // Menu Bar appears when moused to.
        //  .DisableAppleMenu,          // All Apple menu items are disabled.
        .DisableProcessSwitching,      // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
        .DisableForceQuit,             // Cmd+Opt+Esc panel is disabled.
        .DisableSessionTermination,    // PowerKey panel and Restart/Shut Down/Log Out are disabled.
        .DisableHideApplication,       // Application "Hide" menu item is disabled.
        //  .AutoHideToolbar,           
        .FullScreen
    ]
    

    As for the browserWindowController error it simply means that the Swift compiler doesn't know what this variable is. It may have be defined outside the scope of its current usage or even not declared at all.