Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 构建自己的AppleScript数字错误处理_Json_Macos_Applescript - Fatal编程技术网

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