grahamcracker1234
grahamcracker1234

Reputation: 611

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?

Upvotes: 1

Views: 3049

Answers (3)

justinseibert
justinseibert

Reputation: 176

If anyone is dealing with this use-case in the SwiftUI era, I have found that adding

<key>LSUIPresentationMode</key><real>3</real>

in the Info.plist will disable the menu and dock for a fullscreen application.

I found this in the documentation archive with the following value description.

All hidden mode. In this mode, all UI elements are hidden, including the menu bar. Elements do not automatically show themselves in response to mouse movements or user activity.

https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

It appears to still be a part of the active documentation as well:

https://developer.apple.com/documentation/bundleresources/information_property_list/lsuipresentationmode

Upvotes: 0

Bishnu Das
Bishnu Das

Reputation: 171

I have updated the code for swift 4.2. Check it out.

//Enter kiosk mode
func KisokMode(){
    let presOptions: NSApplication.PresentationOptions = [
        .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 = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
    TheWindowExample.contentView?.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary) 
}

TheWindowExample is the window in which you want to work with kiosk mode.

Upvotes: 1

Eric Aya
Eric Aya

Reputation: 70098

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.

Upvotes: 2

Related Questions