Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 122
if {catname} is in otherAccountNames then
try
set otherAccount to POP account catname
on error
try
set otherAccount to IMAP account catname
on error
try
set otherAccount to Exchange account catname
on error
beep 2
return
end try
end try
end try
tell frontWin to set its account to otherAccount
set exitRpt to true
exit repeat
end if
end repeat
end repeat -- 1 times
if exitRpt then exit repeat -- done
end repeat
end tell
Note that the script checks for every recipient. If all you care about is the first To recipient, remove the outer repeat block and exitRpt lines, and
set theRecip to first recipient of frontWin
instead.
AppleScript does not have a 'Next Repeat' operator, so note the trick in the script to effect the same thing by including a repeat 1 times block inside the outer repeat block. That way, when you hit a condition that makes continuation with the current list item unnecessary and undesirable (for example, when no recipient is a contact or group bearing the sought category), the script moves on to the next list item by an exit repeat within the '1 times' repeat block, rolling it forward to the next item in the outer repeat loop.
That's why, when there's a condition that requires exiting the outer repeat block, namely having found both a category and the account of the same name, you first have to set the variable exitRpt to true , exit the inner '1 times' repeat block, and use the true value of exitRpt after the '1 times' block closes as the criterion for exit repeat from the outer block.
Also note that there's no generic account class (although message has an account property), so you need to check for POP account, IMAP account and Exchange account of the designated name in turn.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine