0

I am forced to use Outlook for Mac connected to corporate Exchange at work and I have pieced together a small AppleScript to alter subject lines of incoming email messages from our monitoring system. By default they are of an ungodly length and not human readable. I am attempting to fix that.

The script works, but for some strange reason everything is working great when I send test messages myself, however all changes are reverted back when the real messages from the monitoring system come in! When message arrives into my mailbox the subject is exacly how I want it, but within 3-5 seconds it reverts back to the original subject!

I do not know anything about AppleScript and have no idea where to beging troubleshooting something like this.

Would anyone please take a look and tell me if what I am attempting to do is doable?

on replaceText(find, replace, subject)
    set prevTIDs to text item delimiters of AppleScript
    set text item delimiters of AppleScript to find
    set subject to text items of subject

    set text item delimiters of AppleScript to replace
    set subject to "" & subject
    set text item delimiters of AppleScript to prevTIDs

    return subject
end replaceText

tell application "Microsoft Outlook"
    set theMessages to the current messages
end tell

repeat with theMsg in theMessages
    tell application "Microsoft Outlook"
        set mysubject to get the subject of theMsg
        if mysubject contains "[Subscription:Spectrum CTO] SPECTRUM - " then
            set mysubject to my replaceText("[Subscription:Spectrum CTO] SPECTRUM - ", "", mysubject)
            set mysubject to my replaceText("Alarm Title: ", "", mysubject)
            set mysubject to my replaceText("Severity: ", "", mysubject)
            set mysubject to my replaceText("Model Name:", "-", mysubject)
            set subject of theMsg to the mysubject as string
        end if
    end tell
end repeat
solefald
  • 1,739
  • 1
  • 15
  • 29

2 Answers2

1

Since the only line that alters the message is

set subject of theMsg to the mysubject as string

it seems that it might be an issue with Exchange. Have you tried simply setting the subject of another email when it arrived?

adayzdone
  • 11,120
  • 2
  • 20
  • 37
  • yep. changing messages that are already in my mailbox works fine. they get saved correctly and changes propagated to Exchange. I am under the impression that I change the subject before the message is completely downloaded, so my changes are overwritten. Perhaps I can add a 2-3 second pause... – solefald Aug 29 '12 at 05:37
  • ha! i think i fixed it. I inserted a 3 second delay before it attempted to change the subject! Will test further. – solefald Aug 29 '12 at 05:45
0

Ok, The problem was solved by adding

delay(3)

right before

set subject of theMsg to the mysubject as string

solefald
  • 1,739
  • 1
  • 15
  • 29