美文网首页程序员
mac osx dock栏处理

mac osx dock栏处理

作者: _smoking_ | 来源:发表于2019-04-08 15:37 被阅读0次

    添加程序到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;
    }
    

    深圳利程电子有限公司

    相关文章

      网友评论

        本文标题:mac osx dock栏处理

        本文链接:https://www.haomeiwen.com/subject/aefpiqtx.html