构建自己的AppleScript数值错误处理 [英] Build own AppleScript numerical error handling

查看:103
本文介绍了构建自己的AppleScript数值错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个可以自定义的错误数字,我定义类似于确认项目的应用程序:

I'm wanting to build an app for validating projects using custom error numbers I've defined similar to:

try
    ## do something
on error number -2700
    display dialog "Foobar"
end try

JSON助手的定义列表如下:

tell application "JSON Helper"
    set myJSON to make JSON from {-1232:"missing definition", -123231:"foo", -1232314:"bar" }
    return myJSON
end tell

不过,我没有看到一个方法引用之后做到这一点:

however I do not see a way to do this after referencing:

  • Error Numbers and Error Messages
  • Working with Errors

其他然后用臃肿的条件,如:

other then using a bloated conditional like:

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

研究我无法填充以外的任何<一后href=\"http://apple.stackexchange.com/questions/85682/what-techniques-work-to-handle-errors-in-applescript-so-i-can-place-a-dialog\">What技术合作,以处理AppleScript的错误,所以我可以放置一个对话框?那么有没有在我的AppleScript可以写错误处理类似错误号和错误信息的文件的方法吗?

After researching I was unable to populate anything other than "What techniques work to handle errors in AppleScript so I can place a dialog?" so is there a way in AppleScript I can write error handling similar to Error Numbers and Error Messages documentation?

推荐答案

有可能以属性列表项

该脚本把记录在一个新的物业项目

This script put a record in a new property list item

使用错误号作为字符串得到的值属性列表项

Use the error number as string to get the value in the property list items

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 文件(在 preferences 在本实施例文件夹)。

Here's a script to save a property list items to a PLIST file (In the Preferences folder in this example).

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

这篇关于构建自己的AppleScript数值错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆