Searching about CoreDockPreferences, I found These private system APIs coredock.h
I'm trying to change the value of Minimize To App using CoreDockSetPreferences, but it's not working
Below is my Interface and Implementation in Obj-c:
@interface Symbolic : NSObject
extern void CoreDockSetPreferences(CFDictionaryRef preferenceDict);
- (void) setDictionaryDock: (CFDictionaryRef)dockDict;
@end
@implementation Symbolic
-(void) setDictionaryDock: (CFDictionaryRef)dockDict
{
CoreDockSetPreferences(dockDict);
}
And Here is how I call and pass dock.plist Dictionary Changed in 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)
}
}
CodePudding user response:
Thanks Willeke you're right.
DockDict was not what should be. Reading more about, I answer the question.
Basically I follow the commented "sequence usage" found in coredock.h
// Example usage
/*
CFArrayRef d = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, CFSTR("showRecents,showProcessIndicators,minimizeToApplication"), CFSTR(","));
CFDictionaryRef dic;
CoreDockCopyPreferences(d, &dic, nil);
*/
And re-create the code as below:
@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);
}
and in Swift:
public func setMinimizeToApp(value: Bool){
if var dict = symbolic.getDictionaryDock() as? [String: Bool] {
if dict["minimizeToApplication"] != value{
dict["minimizeToApplication"] = value
symbolic.setDictionaryDock(dict)
}
}
}