mac osx dock栏处理

添加程序到dock栏

- (BOOL)addApplicationToDock:(NSString *)path {
    NSDictionary *domain = [self persistentDomainForName:@"com.apple.dock"];
    NSArray *apps = [domain objectForKey:@"persistent-apps"];
    NSArray *matchingApps = [apps filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K CONTAINS %@", @"tile-data.file-data._CFURLString", path]];
    if ([matchingApps count] == 0) {
        NSMutableDictionary *newDomain = [domain mutableCopy];
        NSMutableArray *newApps = [apps mutableCopy];
        NSDictionary *app = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:path, @"_CFURLString", [NSNumber numberWithInt:0], @"_CFURLStringType", nil] forKey:@"file-data"] forKey:@"tile-data"];
        [newApps addObject:app];
        [newDomain setObject:newApps forKey:@"persistent-apps"];
        [self setPersistentDomain:newDomain forName:@"com.apple.dock"];
        return [self synchronize];
    }
    return NO;
}

判断程序是否保留在dock栏

- (BOOL)isApplicationOnDock:(NSString *)name{
    NSDictionary *domain = [self persistentDomainForName:@"com.apple.dock"];
    NSArray *apps = [domain objectForKey:@"persistent-apps"];
    NSArray *newApps = [apps filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"not %K CONTAINS %@", @"tile-data.file-data._CFURLString", name]];
    if (![apps isEqualToArray:newApps]) {
        return YES;
    }
    return NO;
}

从dock栏移出

- (BOOL)removeApplicationFromDock:(NSString *)name {
    NSDictionary *domain = [self persistentDomainForName:@"com.apple.dock"];
    NSArray *apps = [domain objectForKey:@"persistent-apps"];
    NSArray *newApps = [apps filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"not %K CONTAINS %@", @"tile-data.file-data._CFURLString", name]];
    if (![apps isEqualToArray:newApps]) {
        NSMutableDictionary *newDomain = [domain mutableCopy];
        [newDomain setObject:newApps forKey:@"persistent-apps"];
        [self setPersistentDomain:newDomain forName:@"com.apple.dock"];
        return [self synchronize];
    }
    return NO;
}

深圳利程电子有限公司

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,902评论 1 32
  • 承上启下 唠叨两句,其几天已经写了chrome浏览器的简单安装,和一个神奇的插件:油猴插件,为什么说它是个神奇的插...
    维安tec阅读 5,244评论 8 26
  • ——情人节记 此生何来, 彼岸何在? 时间的巨浪席卷所有, 欢乐和忧伤, 贪婪和渴望, 皆沉于无底深渊。 ...
    月明天山阅读 1,522评论 0 4
  • 没有天才,没有坐享其成。 遇到问题,冷静。 学习理论告诉我们,人,会进步。 现在的不会,不等于将来的不会。 现在的...
    躲进小楼看灯火阅读 1,310评论 0 0

友情链接更多精彩内容