Re: Modifying incoming mail subject
Re: Modifying incoming mail subject
- Subject: Re: Modifying incoming mail subject
- From: "Gary (Lists)" <email@hidden>
- Date: Fri, 28 Dec 2007 16:38:52 -0500
- Thread-topic: Modifying incoming mail subject
"Michaël Grünewald" wrote:
> Thanks for these valuable information, I should pay much attention to
> ruby in the following days. My bet is that Ruby is easier to learn
> than Applescript (I have basics in many computer languages, but
> Applescript is quite disturbing --- or the guidebook quite unclear.)
>
> Back to the problem of modifying incoming emails, my script is still
> not working. To get more clues I have put a few SAY orders in the
> script:
"Mark J. Reed" wrote:
> And you might consider using "display dialog" instead of "say", unless
of
> course you chose the latter due to a visual impairment.
Well, sure, 'considering' it is okay. But I, also, prefer say because I
don't have to click any buttons or wait for a 'with timeout' to expire.
Say is a nice debugging choice, even without any particular visual
differences.
Of course, one has to be in a physical location for which sound is
appropriate.
;)
But see below for an even better way to follow your errors on a shoestring
budget.
> -- SCRIPT
> using terms from application "Mail"
> on perform mail action with messages theMessages for rule theRule
> tell application "Mail"
> say "Hello"
> set text item delimiters to "[Caml-list] "
> repeat with eachMessage in theMessages
> say "This goes on and on"
> set theSubject to the subject of eachMessage
> set theAnswer to ""
> repeat with thePart in text items of theSubject
> set theAnswer to theAnswer & thePart
> end repeat
> set subject of eachMessage to (theAnswer)
> end repeat
> end tell
> end perform mail action with messages
> end using terms from
> -- SCRIPT
>
> When I ask Mail to apply rules, I can hear the "hello" that let me
> know the script is triggered, but there is no iteration of the loop.
> Semantics of the code I wrote is unclear to me because I merely
> patched together lines that I found here and there on the www.
There are 2 loops, but I take it that you must mean the first one (or else
you would have mentioned such, or your "This goes on..." message would have
been spoken.
And so, Mark's question is very appropriate, since there is likely an error
with the 'repeat' loop's parameters.
I mentioned before about debugging with 'say'/'display dialog' and such. On
that note, which can help you and can help us (when communicating problems
to the list) is to learn about the AppleScript control statement 'try'.
'try' is a way to interact with errors, you might say. In its most simple
form, you simply wrap AppleScript in a block, like this:
try
-- some script code line 1
-- some script code line 2
end try
Now, that will watch for errors, and fail without notice if one is
encountered. That is, you won't be notified of the error, but the script
won't bomb. The script would simply continue at the line after the 'end
try'. This can lead to further errors, of course, if some variable were
supposed to be initialized at the "line 2" above, inside the 'try block'
(that's what folks call that construct), since that line may not have been
reached at all if "line 1" had the error.
[For more complete information about 'try', see page 259 of the PDF version
of the _old_ AppleScript Language Guide, dated May 5, 1999. Or the
corresponding section 'Control Statements' > 'try' in some other version.]
So, there is a way to enhance that 'try block' (control statement), to get a
report back about the error.
try
-- code line 1
-- code line 2
on error errMsg_ number errNum_ -- and more, if needed
-- what to do with an error
end try
In the above, "errMsg_" and "errNum_" are my variable names. AppleScript
will supply the values if an error occurs in the 'try block', before 'on
error'.
So, inside the 'on error' handler of that 'try block', you might write:
display dialog errMsg_
...which would display whatever message AS sent back about the error.
Sometimes the error number is useful (but usually no more so than the
description, since the error numbers are cryptic and not well referenced
easily within a script editor.)
So, for example, here is a script that will error, and the resulting notice
to the user:
try
display dialog _hello
on error m number n
say m & ":" & space & n
end try
Will say: "The variable _hello is not defined.: -2753"
(But 'display dialog' may be more useful in this case, depending. I find
the spoken statement for this error entirely acceptable, but seeing the word
"_hello" would be along the lines of your request about spelling errors in
variable names and such. As you like.)
Anyway, Micha, that may be of use to you as you work out just exactly
_where_ your error is being generated inside that 'using terms from' block.
And it will help you communicate about the error here.
Best,
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden