AppleScript的支持本地阅读,并通过系统事件编写的Plist:
use application "System Events" # Avoids tell blocks, note: 10.9 only
property _myPlist : "~/Library/Preferences/com.plistname.plist
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
set plistItemValue to plistItemValue + 1
set value of property list item "plistItem" of contents of property list file _myPlist to plistItemValue
与此唯一的问题是THA它不能创建plists所以如果plist的存在不确定,你需要将它包装在尝试。
try
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
on error -1728 # file not found error
do shell script "defaults write com.plistname.plist plistItem 0"
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
end try
非常感谢! – Tyilo 2011-05-05 19:16:46