【问题标题】:Removing a dock icon in OSX Mavericks programmatically以编程方式删除 OSX Mavericks 中的停靠图标
【发布时间】:2013-10-22 18:49:11
【问题描述】:

有人知道使用脚本或使用 Cocoa 删除新 OSX Mavericks 上任何应用程序的停靠图标的任何方法吗? 我有一个卸载程序,它必须在卸载某些应用程序后删除它们的停靠图标。但是现有的逻辑在 10.9 中失败了。 到目前为止(直到 10.8)我一直在这样做,方法是从 com.apple.dock.plist 中删除图标条目,然后终止扩展坞。但是,它不适用于小牛队。 但是,我可以使用NSUserDefaults 删除该图标,但是当我的应用程序(卸载程序)以提升的权限运行时它也会失败。 任何其他想法/命令/解决方案都会有所帮助。

【问题讨论】:

  • 您找到解决方案了吗?我的公司遇到了完全相同的问题,只是我们试图将一件商品换成另一件。
  • 这里有一些信息:macinstallers.blogspot.in/2013/12/… 当您没有提升的权限时,您必须调用此代码。希望它也对你有用。

标签: cocoa dock osx-mavericks


【解决方案1】:

我修改了上面博客文章中的代码,它可以工作。问题是在 Mavericks 中,-persistentDomainForName: 返回一个不可变的字典,所以我必须让它可变才能让它工作。我把它贴在这里,因为博客文章有可能变成死链接。

- (void)removeDockItemNamed:(NSString *)dockIconLabel
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSMutableDictionary* dockDict = [[userDefaults persistentDomainForName:@"com.apple.dock"] mutableCopy];

    NSMutableArray* apps = [[dockDict valueForKey:@"persistent-apps"] mutableCopy];
    if (apps != nil)
    {
        NSArray* appsCopy = [apps copy];
        bool modified = NO;
        for(NSDictionary *anApp in appsCopy)
        {
            NSDictionary* fileDict = [anApp valueForKey:@"tile-data"];
            if(fileDict != nil)
            {
                NSString *appName = [fileDict valueForKey:@"file-label"];

                if([dockIconLabel isEqualToString:appName])
                {
                    [apps removeObject:anApp];
                    modified = YES;
                    break;
                }
            }
        }
        if(modified)
        {
            //If the dictionary was modified, save the new settings.
            dockDict[@"persistent-apps"] = apps;
            [userDefaults setPersistentDomain:dockDict forName:@"com.apple.dock"];
            //Reset the standardUserDefaults so that the modified data gets synchronized
            //and next time when this function is invoked, we get the up-to-date dock icon details.
            [NSUserDefaults resetStandardUserDefaults];
        }
    }

}

来源:http://macinstallers.blogspot.in/2013/12/remove-dock-icon-using-cocoa.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 2013-02-15
    • 2014-08-10
    相关资源
    最近更新 更多