Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何将一个项添加到字典中,并使用一个键名变量?_Macos_Applescript - Fatal编程技术网

Macos 如何将一个项添加到字典中,并使用一个键名变量?

Macos 如何将一个项添加到字典中,并使用一个键名变量?,macos,applescript,Macos,Applescript,我正在尝试编写一个脚本,将向字典plist添加一个新键。当使用字符串作为字典的键时,脚本运行良好,但我似乎不知道如何使用变量作为键名。下面是脚本,它几乎可以工作了。唯一的问题是能够使用keyName作为变量,而不是字符串文字(它现在正在这样做) 结束plistadvalueforkey试试这个 on pListAddValueForKey(plistFile, keyName, keyValue) if class of plistFile is not text then set pl

我正在尝试编写一个脚本,将向字典plist添加一个新键。当使用字符串作为字典的键时,脚本运行良好,但我似乎不知道如何使用变量作为键名。下面是脚本,它几乎可以工作了。唯一的问题是能够使用keyName作为变量,而不是字符串文字(它现在正在这样做)

结束plistadvalueforkey

试试这个

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

如果我能对这个答案进行两次核对,我会的。应用程序描述的夹板一直在折磨着我。谢谢如果我能对这个答案进行两次核对,我会的。应用程序描述的夹板一直在折磨着我。谢谢