Applescript rules do not work in Tiger

I subscribe to a number of listservs, many of which prepend the subject of a message with its name in brackets, like "[joeslist] Re: some topic."

I have a mail action applescript that removes the listserve name in brackets. It worked with 10.3 but does not work with 10.4. Can anyone more savvy with Applescript and/or Mail tell me what's wrong with it?

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set theorigsubj to subject of eachMessage
if theorigsubj contains "[listserver]" then
try
set thefirstoffset to offset of "]" in theorigsubj
set thelength to the length of theorigsubj
set tempsubj to character (thefirstoffset + 2) of theorigsubj
repeat with counter from (thefirstoffset + 3) to thelength
set thechar to character counter of theorigsubj
set tempsubj to tempsubj & thechar
end repeat
set thenewsubj to tempsubj
end try
set the subject of eachMessage to thenewsubj
end if
end repeat
end tell
end perform mail action with messages
end using terms from

Posted on Aug 24, 2005 5:23 PM

Reply
8 replies

Sep 1, 2005 6:35 PM in response to Austin Kinsella1

No soap. Nothing happens. But here's what I can say now. First, I have rewritten the script, from scratch. Here it is.

using terms from application "Mail"
on perform mail action with messages selectedMsgs
tell application "Mail"
set selCount to (count of selectedMsgs)

if selCount is greater than 0 then
repeat with counter from 1 to selCount

set theMessage to item counter of selectedMsgs
set theorigsubj to subject of theMessage
display dialog theorigsubj
set thelength to the length of theorigsubj

set tempsubj to character 11 of the theorigsubj

repeat with charcounter from 12 to thelength

set thechar to character charcounter of theorigsubj

set tempsubj to tempsubj & thechar

end repeat
set thenewsubj to tempsubj
display dialog thenewsubj
end repeat

set subject of theMessage to thenewsubj
set thedispsubj to subject of theMessage
display dialog thedispsubj
end if
end tell
end perform mail action with messages
end using terms from

using terms from application "Mail"
on run
tell application "Mail" to set sel to selection
tell me to perform mail action with messages (sel)
end run
end using terms from

Next thing. Here's the event log on a test message.

tell application "Mail"
get selection
{message id 10132 of mailbox "Listserv"}
get subject of message id 10132 of mailbox "Listserv"
"[lserver] RE: Review Books"
display dialog "[lserver] RE: Review Books"
{button returned:"OK"}
display dialog "RE: Review Books"
{button returned:"OK"}
set subject of message id 10132 of mailbox "Listserv" to "RE: Review Books"
get subject of message id 10132 of mailbox "Listserv"
"[lserver] RE: Review Books"
display dialog "[lserver] RE: Review Books"
{button returned:"OK"}
end tell

This tells me that the whole error lies in the fact that the script is not (or cannot) change the subject of the message. Any thoughts?

Dave

Sep 2, 2005 4:27 PM in response to David Thiel

Ahhhhh. I think you will find that you can't do that. You certainly can't change the contents, including the subject, of a received message within the mail app - it is making received mails read-only - so Applescript won't be able to do it either, or at least not through mail. Conceivably you could directly edit the message in the mailbox, bypassing the mail application, but this would probably be messy and might have repercussions - screwing up indexes or message ids or something. An alternative approach would be to have the script forward the message to yourself (which would allow it to change the subject), deleting the original.

Sep 28, 2005 4:35 AM in response to David Thiel

Sadly this function has been removed from mail.app

I suggest that you make a request for this feature to reappear at http://www.apple.com/Mac Os X/feedback/

I know about a handful of other people who have made this request as this feature is highly useful in Norway where a Norwegian version of MS Outlook changes the subject, and we - the Mac users of Norway - would like to change it back.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript rules do not work in Tiger

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.