Re: Mysterious OSX Mail scripting problem
Re: Mysterious OSX Mail scripting problem
- Subject: Re: Mysterious OSX Mail scripting problem
- From: Christopher Stone <email@hidden>
- Date: Fri, 25 May 2018 16:11:28 -0500
On 05/24/2018, at 13:45, David Crowe <email@hidden
<mailto:email@hidden>> wrote:
> The following script fails for one of my email accounts. The email works fine
> in OSX Mail, and the message appears to be retrieved properly (first comment)
> but it generates an error when I try to reach inside the message in any way
> (I’m trying to get at the attachments, but I can’t even get the subject). Any
> ideas?
>
> tell application "Mail"
> set theList to selected messages of first message viewer whose index is
> 1
> set aMessage to first item of theList
> aMessage --> «class mssg» id 407896 of «class mbxp» "INBOX" of «class
> mact» "IFAST"
> subject of aMessage --> Mail got an error: Can't get mailbox "INBOX" of
> account "IFAST".
> end tell
Hey David,
Rule-of-the-thumb – never used that method to get selected messages.
It is very fragile, and if you ever have more than one message viewer open it's
going to break.
Index 1 in this case is NOT the front message viewer.
Try this instead:
tell application "Mail"
set selectedMessageList to selection
if selectedMessageList ≠ {} then
set selectedMessage to item 1 of selectedMessageList
tell selectedMessage
set msgSub to subject
end tell
end if
end tell
If you must use a message viewer construct then this is how to make sure the
frontmost one is chosen.
We spent a long time figuring this out many years ago, and Apple hasn't done
anything since then to make it more sensible.
tell application "Mail"
tell (some message viewer whose index is 1)
set msg to item 1 of (get selected messages)
end tell
tell msg
set msgSub to subject
end tell
end tell
Script 1 will work even if the front window is a message.
Script 2 will NOT work UNLESS the message viewer is the FRONTMOST window.
Are you using an IMAP or a POP account?
What happens when you talk to the account like this?
tell application "Mail"
tell account "myGmail"
tell mailbox "INBOX"
set theMsg to first message
tell theMsg
content
end tell
end tell
end tell
end tell
Can you talk to messages other than the selected one?
What version of the macOS are you using?
--
Take Care,
Chris
_______________________________________________
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