I’ve setup a rule to redirect some dept emails to a separate mailbox folder. This works fine. Next I wrote a script to attached to the rule to display an alert when an email is routed to the mailbox. The display dialog component doesn’t work, reading the forums, this is a ‘Mail’ issue, which doesn’t allow for user interaction.
Here’s the script :
tell application "Finder"
set alertresponse to (display dialog "New emails to be viewed" buttons {"soon", "view now"} default button 2)
set button_returned to button returned of alertresponse
-- display dialog button_returned
if button_returned is "view now" then
tell application "Mail"
activate
set selected mailboxes of message viewer 1 to {mailbox "department"} -- of imap account "myAccount"}
end tell
end if
end tell
Is there any workaround for this? If not a ‘display dialog’ is there some other form of alert that can be used?
Yes I did, saved it as an scriptd and then the rule was that when the “from” contained my mail adres. it seems that there is an huge latency between receiving the mail and executing the script, but it works without errors. I think it needs explicitly the tell application “Mail” target to show an alert or dialog in mail, or it is in an bug in newer versions of mail.
tell application "Mail"
set alertresponse to (display dialog "New email to be viewed" buttons {"soon", "view now"} default button 2)
set button_returned to button returned of alertresponse
if button_returned is "view now" then
tell application "Mail"
activate
set selected mailboxes of message viewer 1 to {mailbox "sample dept"} -- of imap account "myAccount"}
end tell
else
tell application "Mail"
activate
tell application "System Events"
tell process "Mail" to keystroke "h" using {command down}
end tell
end tell
end if
end tell