2010-09-19 87 views
1

我想寫一個腳本,將一個新的關鍵字添加到字典plist。當使用字典的字符串作爲字典的鍵時,腳本工作正常,但我似乎無法弄清楚如何使用keyname的變量。腳本在下面,幾乎工作。唯一的問題是能夠使用keyName作爲變量而不是字符串文字(它現在正在執行)。如何用密鑰名稱的變量向字典添加項目?

on pListAddValueForKey(plistFile, keyName, keyValue) 
tell application "System Events" 
     tell property list file plistFile 
      tell contents 
       set previousValue to value 
       set value to (previousValue & {keyName:keyValue}) -- this is the line in need of assistance 
      end tell 
     end tell 
end tell 

末pListAddValueForKey

回答

1

嘗試......

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 
+0

如果我可以把2個檢查這個答案我會的。 AppleScripting plists一直在殺死我。謝謝! – prime31 2010-09-20 15:15:34

+0

很高興我可以幫助uprise! – regulus6633 2010-09-21 04:16:27

相關問題