Macos 如何将一个项添加到字典中,并使用一个键名变量?
我正在尝试编写一个脚本,将向字典plist添加一个新键。当使用字符串作为字典的键时,脚本运行良好,但我似乎不知道如何使用变量作为键名。下面是脚本,它几乎可以工作了。唯一的问题是能够使用keyName作为变量,而不是字符串文字(它现在正在这样做) 结束plistadvalueforkey试试这个Macos 如何将一个项添加到字典中,并使用一个键名变量?,macos,applescript,Macos,Applescript,我正在尝试编写一个脚本,将向字典plist添加一个新键。当使用字符串作为字典的键时,脚本运行良好,但我似乎不知道如何使用变量作为键名。下面是脚本,它几乎可以工作了。唯一的问题是能够使用keyName作为变量,而不是字符串文字(它现在正在这样做) 结束plistadvalueforkey试试这个 on pListAddValueForKey(plistFile, keyName, keyValue) if class of plistFile is not text then set pl
on pListAddValueForKey(plistFile, keyName, keyValue)
if class of plistFile is not text then set plistFile to plistFile as text
tell application "System Events"
tell property list file plistFile
tell contents
make new property list item at end of property list items with properties {name:keyName, value:keyValue}
end tell
end tell
end tell
end pListAddValueForKey
试试这个
on pListAddValueForKey(plistFile, keyName, keyValue)
if class of plistFile is not text then set plistFile to plistFile as text
tell application "System Events"
tell property list file plistFile
tell contents
make new property list item at end of property list items with properties {name:keyName, value:keyValue}
end tell
end tell
end tell
end pListAddValueForKey
如果我能对这个答案进行两次核对,我会的。应用程序描述的夹板一直在折磨着我。谢谢如果我能对这个答案进行两次核对,我会的。应用程序描述的夹板一直在折磨着我。谢谢