通过apple脚本在info.plist中设置URLTypes的值

时间:2011-10-11 14:40:50

标签: scripting applescript

我想在info.plist文件中为URLTypes设置值,如下所示

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.test.testLaunch</string>
</dict>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>LaunchApp1</string>
<string>LaunchApp2</string>
</array>
</dict>
</array>

我正在尝试以下方法,但它不起作用。

tell property list file plistFile
tell contents
set value of property list item "CFBundleURLTypes" of property list item "CFBundleURLName" to "New Key Value"
end tell
end tell

如何设置CFBundleURLTypes键的所有值并设置字典和数组的嵌套值。

1 个答案:

答案 0 :(得分:2)

applescript等价物是array = list和dictionary = record,所以只需创建一个记录列表。一个记录的值为字符串,另一个记录的值为字符串数组。注意:我没有对此进行过测试,但值得一试。

set myArray to {{CFBundleURLName:"com.test.testLaunch"}, {CFBundleURLSchemes:{"LaunchApp1", "LaunchApp2"}}}
tell application "System Events"
    set plistFile to property list file "some:path"
    tell plistFile
        tell contents
            set value of property list item "CFBundleURLTypes" to myArray
        end tell
    end tell
end tell