我有一个完全愚蠢的问题让我疯了。我需要访问plist文件中的一个节点,如果出现问题,我想要一个显示“' stop'图标。这是代码:
tell application "System Events"
tell property list file (plistFile as text)
try
tell contents
set backupDayTemp to value of property list item plistElementBackupDay of property list item chosenBackupDisk
end tell
on error m number n from f to t partial result p
if n = -1728 then
display dialog "Can't find " & plistElementBackupDay & " key for disk " & chosenBackupDisk & " in plist file." buttons {"Damn", "Oh dear"} default button "Damn" with title myName with icon stop
return
else
-- otherwise, pass the error on
error m number n from f to t partial result p
end if
end try
end tell
end tell
似乎编译器认为系统事件应该理解令牌"停止",因为它是用粗体蓝色字体,而不是它通常所用的紫色斜体。当错误处理程序运行时,我被告知"系统事件出错:属性列表文件[文件路径]不理解"停止"消息"
我的问题是:我如何告诉系统事件令牌不适合它?我已经尝试在tell me to
前面放display dialog
,但这并没有帮助。我也试过using terms from application "Standard Additions"
但是当我运行它时,我被要求找到标准添加词典。
撕掉我的头发!!!
答案 0 :(得分:0)
最简单的解决方案是将错误处理放在应用程序告诉块
之外try
tell application "System Events"
tell property list file (plistFile as text)
tell contents
set backupDayTemp to value of property list item plistElementBackupDay of property list item chosenBackupDisk
end tell
end tell
end tell
on error m number n from f to t partial result p
if n = -1728 then
display dialog "Can't find " & plistElementBackupDay & " key for disk " & chosenBackupDisk & " in plist file." buttons {"Damn", "Oh dear"} default button "Damn" with title myName with icon stop
return
else
-- otherwise, pass the error on
error m number n from f to t partial result p
end if
end try