是否可以保存在AppleScript中创建的应用程序的某种设置?
这些设置应在脚本开始时加载,并在脚本结束时保存。
示例:
if loadSetting("timesRun") then
set timesRun to loadSetting("timesRun")
else
set timesRun to 0
end if
set timesRun to timesRun + 1
display dialog timesRun
saveSetting("timesRun", timesRun)其中对话框在第一次运行脚本时显示1,第二次运行时显示2...
函数loadSetting和saveSetting就是我需要的函数。
发布于 2011-05-06 02:25:23
脚本properties是永久性的,但是只要重新保存脚本,保存的值就会被脚本中指定的值覆盖。运行:
property |count| : 0
display alert "Count is " & |count|
set |count| to |count| + 1几次,重新保存,然后再运行几次。
如果要使用用户默认系统,可以使用do shell script "defaults ..."命令或(如果使用Applescript Studio) default entry "propertyName" of user defaults。在Applescript Studio中,您可以使用bind values to user defaults。
发布于 2012-10-19 20:03:24
这也工作得很好(请查看提示的第一条注释):
http://hints.macworld.com/article.php?story=20050402194557539
它使用"defaults“系统,您可以在~/Library/Preferences中获取您的首选项
发布于 2014-01-11 09:49:53
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唯一的问题是它不能创建plist,所以如果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 tryhttps://stackoverflow.com/questions/5902202
复制相似问题