gpt4 book ai didi

macos - 使用终端或 bash 脚本创建和写入 .plist

转载 作者:行者123 更新时间:2023-11-29 09:07:00 27 4
gpt4 key购买 nike

我需要在安装后创建一个 .plist 文件,我唯一可以使用的选项是 bash 脚本。我必须使用 bash 脚本在 /Library/launchAgents 中创建一个 foo.plist 并且我使用了以下命令:

cd /Library/launchAgents
touch foo.plist

现在我需要将内容写入此 .plist 文件,例如:

".plist contents" >> foo.plist

是否有可以在终端中执行此操作的命令?

最佳答案

PlistBuddy 是您想要的。

/usr/libexec/PlistBuddy Info.plist
File Doesn't Exist, Will Create: Info.plist

然后像这样在文件中添加一个条目,

/usr/libexec/PlistBuddy -c 'add CFBundleIdenfier string com.tencent.myapp' Info.plist

顺便说一下,man plistman plutil 可能对你有帮助。

Command Format:
Help - Prints this information
Exit - Exits the program, changes are not saved to the file
Save - Saves the current changes to the file
Revert - Reloads the last saved version of the file
Clear [<Type>] - Clears out all existing entries, and creates root of Type
Print [<Entry>] - Prints value of Entry. Otherwise, prints file
Set <Entry> <Value> - Sets the value at Entry to Value
Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
Copy <EntrySrc> <EntryDst> - Copies the EntrySrc property to EntryDst
Delete <Entry> - Deletes Entry from the plist
Merge <file.plist> [<Entry>] - Adds the contents of file.plist to Entry
Import <Entry> <file> - Creates or sets Entry the contents of file

Entry Format:
Entries consist of property key names delimited by colons. Array items
are specified by a zero-based integer index. Examples:
:CFBundleShortVersionString
:CFBundleDocumentTypes:2:CFBundleTypeExtensions

Types:
string
array
dict
bool
real
integer
date
data

Examples:
Set :CFBundleIdentifier com.apple.plistbuddy
Sets the CFBundleIdentifier property to com.apple.plistbuddy
Add :CFBundleGetInfoString string "App version 1.0.1"
Adds the CFBundleGetInfoString property to the plist
Add :CFBundleDocumentTypes: dict
Adds a new item of type dict to the CFBundleDocumentTypes array
Add :CFBundleDocumentTypes:0 dict
Adds the new item to the beginning of the array
Delete :CFBundleDocumentTypes:0 dict
Deletes the FIRST item in the array
Delete :CFBundleDocumentTypes
Deletes the ENTIRE CFBundleDocumentTypes array

关于macos - 使用终端或 bash 脚本创建和写入 .plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27379507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com