开发者

set values for URLTypes in info.plist through apple script

开发者 https://www.devze.com 2023-04-12 19:06 出处:网络
I want to set the values in info.plist file for URLTypes like below <key>CFBundleURLTypes</key>

I want to set the values in info.plist file for URLTypes like below

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.test.testLaunch</string>
</dict>
<dict>
<key>CFBundleURLSchemes&开发者_开发问答lt;/key>
<array>
<string>LaunchApp1</string>
<string>LaunchApp2</string>
</array>
</dict>
</array>

I am trying the below approach but it does not work.

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

What should I do to set all the values for the CFBundleURLTypes key and set the nested values for dictionary and array.


The applescript equivalents are array = list and dictionary = record, so just make a list of records. One record has a value of a string and the other one has a value of an array of strings. Note: I haven't tested this but it's worth a try.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号