> Here is the whole (short) script, so you can see context of what variables
> I'm feeding.
>
- <script: ill wrapped, I'm sure>
The way to avoid that is to change into HTML after pasting in: gets rid of fancy formatting, but keeps soft-wrapping.
See below.
property replyAcct : ""
tell application "Microsoft Entourage"
if replyAcct = "" then -- get an acct from the pop-up
if class of front window is not draft window then
display dialog "Open a message draft window (or click reply to an existing message). Set the account pop-up to the account that you would like this script to use, then run the script again." buttons {"OK"} default button "OK" with icon 1
else -- if draft window is open in the front
display dialog "You selected \"" & name of account of front window & "\" as the account you want this script to use. Is that correct?" buttons {"Yep", "Nope", "Cancel"} default button "Yes"
if button returned of result is "No" then
display dialog "Set the account pop-up in the current message to the account you'd like this script to use, and then run the script again." buttons {"Cancel"} default button "Cancel" with icon 1
else
if button returned of result is "Yes" then
set replyAcct to account of front window -- set the property to the chosen account
display dialog "I have registered \"" & replyAcct & "\" as the acct to use when this script is invoked." buttons {"OK"} default button "OK" with icon 1
end if
end if
end if
else -- an acct property exists, so do it
if class of front window is draft window then -- we're cool
set theMsgWin to front window -- does this coerce text?
set account of theMsgWin to replyAcct -- here we do the actual
change
else -- Doh!
beep
display dialog "I can't change the account, because there is no new message window in front." buttons {"OK"} default button "OK" with icon 0
end if
end if
end tell
-----------------------
Script debugging in Smile editor:
There are a few problems. The first one is that the script gets a parameter error here:
display dialog "You selected \"" & name of account of front window & "\" as the account you want this script to use. Is that correct?" buttons {"Yep", "Nope", "Cancel"} default button "Yes"
since there is no button called "Yes". The script won't work at all past that point. If I change that default button to "Yep", then I get the dialog asking me 'You selected "Silcom" as the account you want this script to use. Is that correct?' I clicked Yep. But then the variable 'replyAcct' never got changed from "" because there was no contigency for my clicking "Yep", only for "No" and "Yes". If I change this line:
if button returned of result is "Yes" then
to
if button returned of result is "Yep" then
then I get another error:
"Can't make POP account id 2 into a string", which is same error you got. So I imagine you must have had all "Yep" or all "Yes" at some point to get this far. The error is here:
display dialog "I have registered \"" & replyAcct & "\" as the acct to use when this script is invoked." buttons {"OK"} default button "OK" with icon 1
since the variable 'replyAcct' is a POP account class, and not a string, which is what display dialog needs. Now you have already correctly set the replyAcct property to the right POP account, so that's why the script works on subsequent runs. The error is just here in the set-up part of the script, after you've correctly set the account. What you want is this:
display dialog "I have registered \"" & (name of replyAcct) & "\" as the acct to use when this script is invoked." buttons {"OK"} default button "OK" with icon 1
Now I get the proper dialog telling me:
'I have registered "Silcom" as the acct to use when this script is invoked.'
There was no error at all with the lines you quoted last time, which is why the script worked correctly on later runs, since the replyAcct property had been correctly set before the error stopped the first run of the script. You just need to change
replyAcct
to
(name of replyAcct)
in the set-up dialog above, ad make sure that "Yep" and "Yes" are consistent. Otherwise, it's a fine script.
--
Paul Berkowitz
