Json 构建自己的AppleScript数字错误处理
我想构建一个应用程序,使用我定义的自定义错误号验证项目,类似于:Json 构建自己的AppleScript数字错误处理,json,macos,applescript,Json,Macos,Applescript,我想构建一个应用程序,使用我定义的自定义错误号验证项目,类似于: try ## do something on error number -2700 display dialog "Foobar" end try 通过将列表定义为: tell application "JSON Helper" set myJSON to make JSON from {-1232:"missing definition", -123231:"foo", -1232314:"bar" }
try
## do something
on error number -2700
display dialog "Foobar"
end try
通过将列表定义为:
tell application "JSON Helper"
set myJSON to make JSON from {-1232:"missing definition", -123231:"foo", -1232314:"bar" }
return myJSON
end tell
但是,在参考以下内容后,我看不到这样做的方法:
try
open for access file "MyFolder:AddressData" with write permission
on error msg number n from f to t partial result p
if n = -49 then -- File already open error
display dialog "I'm sorry but the file is already open."
else
error msg number n from f to t partial result p
end if
end try
在研究之后,我无法填充除“”以外的任何内容,所以在AppleScript中是否有一种方法可以编写类似于错误编号和错误消息文档的错误处理 可以使用
属性列表项
此脚本将记录放入新的属性列表项中
将错误号用作字符串以获取属性列表项中的值
set myRecord to {|-1232|:"missing definition", |-123231|:"foo", |-1232314|:"bar", |-49|:"I'm sorry but the file is already open.", |-43|:"This file wasn’t found."}
tell application "System Events" to set myPlist to make new property list item with properties {kind:record, value:myRecord}
try
open for access file "MyFolder:AddressData" with write permission
on error number n
tell application "System Events" to set r to value of first property list item of myPlist whose its name is (n as text)
display alert r
end try
JMichaelTX的问题 下面是一个脚本,用于将
属性列表项
保存到PLIST文件中(在本例的首选项文件夹中)
set plistPath to (path to preferences folder as string) & "errorsMsgs.plist"
tell application "System Events"
set myPlist to make new property list item with properties {kind:record, value:myRecord}
make new property list file with properties {contents:myPlist, name:plistPath}
end tell