在 Apple Mail applescript 中获取规则列表

Get Rule List in AppleMail applescript

正在尝试获取 select 邮件规则

的对话框
set ruleList to {}

tell application "Mail" to set end of ruleList to every rule

set theRule to choose from list ruleList

获取错误

error "Can’t make {«class rule» "Rule 1" of application "Mail", «class rule» "Rule 2" of application "Mail", «class rule» "Rule 3" of application "Mail"} into type string." number -1700 from {«class rule» "Rule 1", «class rule» "Rule 2", «class rule» "Rule 3"} to string

尝试使用

set oldDelimits to AppleScript's text item delimiters
set AppleScript's text item delimiters to "     "
set aRule to (ruleList as string)
set AppleScript's text item delimiters to oldDelimits

仍然是类似的错误,还尝试将分隔符设置为应用程序“邮件”的“”,规则“” 及其组合(双引号用反斜杠转义),没有任何效果

任何建议

干杯

Mail 规则是一个具有各种元素和属性的对象(有关详细信息,请参阅 Mail 的脚本字典),但是 choose from list 对话框的项目需要 text。规则属性之一是其 name,可用于对话框。

以下处理程序获取对话框的规则名称,对话框中的选择用于 return 规则:

to getMailRule() -- choose rule by name
    tell application "Mail"
        set choice to (choose from list (get name of every rule))
        if choice is false then -- cancel
            return missing value
        else
            return first item of (get rules whose name is (choice as string))
        end if
    end tell
end getMailRule

return properties of getMailRule() -- do something with a Mail rule