Reputation: 19
Trying to get a dialog to select Mail Rule
set ruleList to {}
tell application "Mail" to set end of ruleList to every rule
set theRule to choose from list ruleList
Get error
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
Tried using
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
Still similar error, also tried setting delimiter to "" of application "Mail", rule "" & its combination( where double quotes were escaped with backslash), nothing worked
any suggestions
Cheers
Upvotes: 0
Views: 64
Reputation: 3422
A Mail rule is an object that has various elements and properties (refer to Mail's scripting dictionary for more information), but the items for a choose from list
dialog need to be text. One of the rule properties is its name
, which can be used for the dialog.
The following handler gets the rule names for the dialog, and the choice from the dialog is used to return the rule:
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
Upvotes: 0