Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple Mail Script Not Working



Ken, 

Here's a script I use to announce the subject lines of emails as they come in.  I think you can modify it for your use:

using terms from application "Mail"
on perform mail action with messages theMessages for rule ruleName
--we'll use a try block and catch any errors, since Mail doesn't report errors in applescripts
set theVol to get volume settings
set readAloud to not (output muted of theVol)
if readAloud then
try
copy theMessages to messageList
set messageCount to (length of messageList)
tell application "Mail"
if messageCount is 0 then
set theText to "No messages selected."
say theText
else
repeat with aMessage in messageList
set theSubject to (the subject of aMessage) as text
set theBox to (name of account of mailbox of aMessage) as text
set theText to (theBox & space & theSubject) as text
say theText
end repeat
end if
end tell
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
end try
end if
end perform mail action with messages
end using terms from

Also, you should use a try...on error block for at least some part of your code because Mail won't report scripting errors if your script crashes.  You will need to intercept errors yourself and give yourself an error dialog to find out what is happening.


On Aug 30, 2007, at 2:02 PM, email@hidden wrote:
Message: 4
Date: Thu, 30 Aug 2007 13:47:48 -0400
From: Ken Tozier <email@hidden>
Subject: Simple mail script not working
To: Applescript-Users <email@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

Hi

It's been awhile since I used Applescript and I'm having trouble with  
a simple mail script test. Basically, what I want to do is run a  
script when emails with a specific subject line arrives but the  
script doesn't seem to get called.

Here's what I did
- Set up a rule in the Mail prefs with the settings:
Subject contains testing123
Run Applescript: "/Library/Scripts/Mail Scripts/testing123.scpt

- Send a message to myself with the "testing123" subject line
- Result: Nothing

Here's the script could someone point out what I'm doing wrong?

using terms from application "Mail"
on perform mail action with messages selectedMessages
-- activate -- tried this both commented and uncommented, no  
difference
repeat with aMessage in selectedMessages
display dialog aMessage
end repeat
end perform mail action with messages
end using terms from

Thanks for any help

Ken




------------------------------

Message: 5
Date: Thu, 30 Aug 2007 14:16:15 -0400
From: Ken Tozier <email@hidden>
Subject: Re: Simple mail script not working
To: Applescript-Users <email@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

Yikes! The "RunApplescript" rule seems to be extremely buggy. It  
crashes Mail instantaneously whenever it gets an email. I actually  
had to go into my mail folder through Comcast, delete the message,  
launch Mail and delete the rule before Mail became stable again.

Guess it's not ready for prime time. I sent the crash log to Apple.

On Aug 30, 2007, at 1:47 PM, Ken Tozier wrote:

Hi

It's been awhile since I used Applescript and I'm having trouble  
with a simple mail script test. Basically, what I want to do is run  
a script when emails with a specific subject line arrives but the  
script doesn't seem to get called.

Here's what I did
- Set up a rule in the Mail prefs with the settings:
Subject contains testing123
Run Applescript: "/Library/Scripts/Mail Scripts/testing123.scpt

- Send a message to myself with the "testing123" subject line
- Result: Nothing

Here's the script could someone point out what I'm doing wrong?

using terms from application "Mail"
on perform mail action with messages selectedMessages
-- activate -- tried this both commented and uncommented, no  
difference
repeat with aMessage in selectedMessages
display dialog aMessage
end repeat
end perform mail action with messages
end using terms from

Thanks for any help

Ken
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.