2
votes

I am trying to hide the dock, and menu/spotlight bar at the top of the screen and basically go into kiosk mode for my Cocoa OS X app. However, I don't want to activate full-screen mode. I want the app to run as normal, but simply hide the dock and the menu/spotlight area on the desktop to discourage users from using them. I have tried a variety of options and I can't seem to get it to work.

https://developer.apple.com/library/mac/technotes/KioskMode/Introduction/Introduction.html

It seems like most implementations of this code require going into full-screen or are in Objective C. Is there a way of doing this in Swift without going into Full-screen mode?

  • Update - I figured out how to do it! I could hide the menu using NSMenu but I had to hide the dock by accessing the terminal. There may be an easier and cleaner way of doing it, but I was unable to find one. I hope this helps anyone else looking for a solution!

     import Cocoa
    
    @NSApplicationMain
     class AppDelegate: NSObject, NSApplicationDelegate {
    
       var datastring = NSString()
    
    
    func applicationDidFinishLaunching(aNotification: NSNotification) {
    
    let task = NSTask()
    let pipe = NSPipe()
    task.standardOutput = pipe
    
    task.launchPath = "/bin/bash/"
    task.arguments = ["defaults write com.apple.dock tilesize -int 1", "killall -Kill Dock"]
    
    let file:NSFileHandle = pipe.fileHandleForReading
    
    task.launch()
    task.waitUntilExit()
    
    let data =  file.readDataToEndOfFile()
    datastring = NSString(data: data, encoding: NSUTF8StringEncoding)!
    
    // Insert code here to initialize your application
     }
    
    func applicationWillTerminate(aNotification: NSNotification) {
    // Insert code here to tear down your application
      }
    
    override func awakeFromNib() {
    
     NSMenu.setMenuBarVisible(false)
    
    }
      }
    }
    
2
The menu can be hidden in preferences. Maybe a scrip can hide it.john elemans
I was able to hide the menu from NSMenu, but I am still not able to hide the dock.cheesydoritosandkale
These commands will change dock settings, but I'm not sure how to hide it on command; defaults write com.apple.dock autohide -bool true defaults write com.apple.dock autohide-delay -float 0 defaults write com.apple.dock autohide-time-modifier -float 0 (linebreaks before each 'defaults')john elemans
Thanks John! I figured out how to do it by accessing the terminal.cheesydoritosandkale
Nice. Nuclear option!john elemans

2 Answers

0
votes

I figured out how to do it! I could hide the menu using NSMenu but I had to hide the dock by accessing the terminal. There may be an easier and cleaner way of doing it, but I was unable to find one. I hope this helps anyone else looking for a solution.

  import Cocoa

   @NSApplicationMain
   class AppDelegate: NSObject, NSApplicationDelegate {

  var datastring = NSString()


  func applicationDidFinishLaunching(aNotification: NSNotification) {

  let task = NSTask()
  let pipe = NSPipe()
  task.standardOutput = pipe

  task.launchPath = "/bin/bash/"
  task.arguments = ["defaults write com.apple.dock tilesize -int 1", 
   "killall -Kill Dock"]

 let file:NSFileHandle = pipe.fileHandleForReading

  task.launch()
  task.waitUntilExit()

  let data =  file.readDataToEndOfFile()
  datastring = NSString(data: data, encoding: NSUTF8StringEncoding)!

  }

   func applicationWillTerminate(aNotification: NSNotification) {
  }

 override func awakeFromNib() {

 NSMenu.setMenuBarVisible(false)

 }
  }
 }
0
votes

Is the following what you're looking for?

Swift 3:

func applicationWillFinishLaunching(_ notification: Notification) {
    NSApp.presentationOptions = [.autoHideDock, .autoHideMenuBar]
}

Swift 2:

func applicationWillFinishLaunching(notification: NSNotification) {
    NSApp.presentationOptions = [.AutoHideDock, .AutoHideMenuBar]

}

(Comment everything else out in your code, or at least the code you included here).