搜索CoreDockPreferences,我发现这些私有系统api coredock.h
我试图使用CoreDockSetPreferences改变最小化到应用程序的值,但它不工作
下面是我在Obj-c中的接口和实现:
@interface Symbolic : NSObject
extern void CoreDockSetPreferences(CFDictionaryRef preferenceDict);
- (void) setDictionaryDock: (CFDictionaryRef)dockDict;
@end
@implementation Symbolic
-(void) setDictionaryDock: (CFDictionaryRef)dockDict
{
CoreDockSetPreferences(dockDict);
}
下面是我如何调用和传递dock。plist Dictionary在Swift中更改:
func dockPrefChange(){
if let dir = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first {
let dockPlistPath = dir.appendingPathComponent("Preferences", isDirectory: true).appendingPathComponent("com.apple.dock.plist", isDirectory: false)
guard let dockDictionary = NSMutableDictionary(contentsOf: dockPlistPath) else {return}
dockDictionary["minimize-to-application"] = 1
Symbolic().setDictionaryDock(dockDictionary as CFDictionary)
}
}
谢谢Willeke,你是对的。
DockDict不是应该是什么。阅读更多关于,我回答这个问题。
基本上我遵循注释的"序列用法"。coredock.h
// Example usage
/*
CFArrayRef d = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, CFSTR("showRecents,showProcessIndicators,minimizeToApplication"), CFSTR(","));
CFDictionaryRef dic;
CoreDockCopyPreferences(d, &dic, nil);
*/
并重新创建如下代码:
@implementation Symbolic
- (NSDictionary*) getDictionaryDock
{
CFArrayRef d = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, CFSTR("showRecents,showProcessIndicators,minimizeToApplication"), CFSTR(","));
CFDictionaryRef dic;
CoreDockCopyPreferences(d, &dic, nil);
NSDictionary *nsDictionary = (__bridge NSDictionary*)dic;
return nsDictionary;
}
- (void) setDictionaryDock: (NSDictionary*) newDictionary
{
CFDictionaryRef dict = (__bridge CFDictionaryRef)newDictionary;
CoreDockSetPreferences(dict);
}
和在Swift中:
public func setMinimizeToApp(value: Bool){
if var dict = symbolic.getDictionaryDock() as? [String: Bool] {
if dict["minimizeToApplication"] != value{
dict["minimizeToApplication"] = value
symbolic.setDictionaryDock(dict)
}
}
}