Reputation: 224
I'm writing a script using the Mail applescript template (File > New from template > Mail > Mail Rule Action.scptd) but it doesn't seem like the examples in the template are working
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
set the message_count to the count of these_messages
repeat with i from 1 to the message_count
set this_message to item i of these_messages
try
set this_subject to (subject of this_message) as Unicode text
if this_subject is "" then error
on error
set this_subject to "NO SUBJECT"
end try
say this_subject
end repeat
end tell
end perform mail action with messages
end using terms from
It says "no subject" even if the message has a subject. I'm using OS X 10.7.2 and Mail 5.1. Any suggestions?
Upvotes: 1
Views: 5738
Reputation: 21
I have this working under 10.8.2 (Mail 6.2) if it helps at all? This is the code I'm using:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
try
set this_subject to subject of eachMessage
if this_subject is "" then error
on error
set this_subject to "No subject."
end try
say this_subject
end repeat
end tell
end perform mail action with messages
end using terms from
Hope that helps?
Upvotes: 2
Reputation: 66
Try adding delay 3
under set this_subject to (subject of this_message) as Unicode text
. It may be that Mail doesn't have time to process the message to get the subject line before moving to the next command.
If this works, you may not need 3 seconds. You can experiment with decreasing the delay time. Note that you can use decimals, as in 1.8.
Upvotes: 1