1
如果您在Dock上进行辅助点击,则可以单击Turn Hiding On
选项自动隐藏Dock。或者,您可以前往System Preferences > Dock
并点击Automatically hide and show the Dock
。通过程序从应用程序中停靠Dock“Turn Hiding On”
我想从我正在制作的应用程序(基本上是一个状态栏图标应用程序)中模拟该功能,最好是在Swift中。
到目前为止,我已经写打开Dock中自动隐藏功能的代码如下:
// Update the value for key "autohide" in com.apple.dock.plist, located in ~/Library/Preferences/.
var dict = NSUserDefaults.standardUserDefaults().persistentDomainForName("com.apple.dock")
dict.updateValue(true, forKey: "autohide")
NSUserDefaults.standardUserDefaults().setPersistentDomain(dict, forName: "com.apple.dock")
// Send notification to the OS.
dispatch_async(dispatch_get_main_queue()) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), "com.apple.dock.prefchanged", nil, nil, true)
}
代码的第一部分在plist文件更新的值,我已确认那是行得通的。第二部分向操作系统发送通知,告诉它该plist中的值已更改,我也已确认该值正在工作。
但是,这两件事并没有让Dock隐藏起来,让我相信我需要做别的事情。或者让我的方法解决问题是错误的?我如何让Dock开始隐藏?
PS:我看过一些关于所谓CoreDock一个私人的,未公开的API,但我想避免走回头路,因为这可能会导致很多问题......
甜。这工作,我只需要几行代码'NSAppleScript'。 – CrazyJony