Wong's Blog

Always on the way forward
  1. 首页
  2. Macos
  3. 正文

Mac原生程序PlistBuddy修改info.plist

2023 年 4 月 12 日 121点热度 0条评论

PlistBuddy 是 Mac 自带的专门解析 plist 的工具,由于 PlistBuddy 并未在 Mac 中默认配置,所以需要通过绝对路径来引用,PlistBuddy的路径所在:

/usr/libexec/PlistBuddy

示例演示

代码

NSServices
Array {
    Dict {
        NSMessage = decompressFiles
        NSKeyEquivalent = Dict {
            default = X
        }
        NSPortName = MacZip
        NSRequiredContext = Dict {
            NSTextContent = FilePath
        }
        NSMenuItem = Dict {
            default = Decompress with MacZip
        }
    }
    Dict {
        NSMenuItem = Dict {
            default = Compress with MacZip
        }
        NSRequiredContext = Dict {
            NSTextContent = FilePath
        }
        NSSendTypes = Array {
            NSFilenamesPboardType
            public.directory
        }
        NSPortName = MacZip
        NSSendFileTypes = Array {
            public.content
            public.directory
        }
        NSMessage = compressFiles
        NSKeyEquivalent = Dict {
            default = Y
        }
    }
}

打印显示

cd desktop    //进入info.plist所在文件夹
/usr/libexec/PlistBuddy -c 'Print :NSServices' info.plist   //显示NSServices所有代码
/usr/libexec/PlistBuddy -c 'Print :NSServices:0' info.plist
结果:
Dict {
        NSMessage = decompressFiles
        NSKeyEquivalent = Dict {
            default = X
        }
        NSPortName = MacZip
        NSRequiredContext = Dict {
            NSTextContent = FilePath
        }
        NSMenuItem = Dict {
            default = Decompress with MacZip
        }
    }
//数组array中第一个Dict
/usr/libexec/PlistBuddy -c 'Print :NSServices:0:NSMenuItem' info.plist
结果:
Dict {
    default = Decompress with MacZip
}
//NSMenuItem中的内容
/usr/libexec/PlistBuddy -c 'Print :NSServices:0:NSMenuItem:default' info.plist
结果:
Decompress with MacZip
//default对应的内容

修改参数

/usr/libexec/PlistBuddy -c 'set :NSServices:0:NSMenuItem:default "解压文件"' info.plist
结果:
Dict {
    default = 解压文件
}

删除参数

/usr/libexec/PlistBuddy -c 'delete :NSServices:0:NSMenuItem:default' info.plist
结果:
Dict {
    
}

增加参数

/usr/libexec/PlistBuddy -c 'add :NSServices:0:NSMenuItem:test string hello' info.plist
结果:
Dict {
    default = Decompress with MacZip
    test = hello
}
标签: 暂无
最后更新:2023 年 4 月 12 日

wong

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
  • Linux / 6篇
  • Macos / 7篇
  • Windows / 9篇
  • 其他 / 9篇

在路上 | 2024