'can't get sender of message 37 in mailbox...'
tell application "Mail"
set selMessage to selection
set senderName to (get sender of selMessage)
end tell
The funny thing is that it works if I explicitly assign selMessage:
set selMessage to (message 47 of mailbox "INBOX" of account "My Account")
For some reason 'selection' is returning an object that won't respond to
'get sender'
Any ideas? I am surprised that Mail.app does not seem to be recordable...
Thanks for any suggestions!
> 'can't get sender of message 37 in mailbox...'
>
> tell application "Mail"
> set selMessage to selection
> set senderName to (get sender of selMessage)
> end tell
>
> The funny thing is that it works if I explicitly assign selMessage:
>
> set selMessage to (message 47 of mailbox "INBOX" of account "My Account")
>
> For some reason 'selection' is returning an object that won't respond to
> 'get sender'
Selection returns a *list* of messages, since several messages can be
selected at once. You can either loop through every message in the
selection, or only take the first one, as this example shows:
tell application "Mail"
set mymsglist to selection
set mymsg to item 1 of mymsglist
sender of mymsg
end tell
Hope this helps,
Eric.
--
Use mekka at mac dot com to reply.
http://homepage.mac.com/mekka/mekkablue
Yes! that did the trick. In hindsight the error message was something like
could not get sender of {message 1 of ...}
I presume now that the curly braces indicate a list. Where would this have
been documented? I looked through an awful lot of documentation and never
saw an indication that selection returned a list. I'm just asking because
maybe there's a good source of info I missed.
Thanks for the very helpful reply.
Eric
While we are on the topic, do you know what applescript command is
appropriate to move a message to another folder?
In my case I need to move the message to an imap folder (I use imap so that
Mail.app can see my pine folders - which happen to be on the local hard
drive - and want to keep storing messages in these folders). Thanks again!
For the record I finally did come up with a script to get the email address
prefix and move a messsage to an imap folder with that name (e.g. Messages
from jsm...@foo.org go into the folder 'jsmith'). This was basically to
replicate the default fcc and message save functions in pine, so that I can
use both pine and Mail.app to access my inbox on an imap server and also see
a set of mbox folders on my local hard drive. I did not want to import my
folders to the Mail.app format because I have many and it seemed like a pain
to get folder browsing of Mail.app folders to work in pine. My solution was
to run the Wash U imap server on my mac so that Mail.app can see my pine
folders (with the imap home dir set appropriately). Now when I read mail
with Mail.app I file it using the script below (also works on stuff in the
'Sent' folder - messages I send are filed by primary recipient). Anyhow I
hope this will help someone - I did not find a lot on moving Mail.app
messages to different folders using Applescript but it seems to work well.
Here is the script (watch out for line wraps):
(* script to move a message into a folder whose name is the sender's email
address
up to the '@' symbol *)
set userName to "myname"
tell application "Mail"
set messageList to selection
repeat with theMessage in messageList
--set theMessage to item 1 of messageList
set senderName to (sender of theMessage)
set recipientName to (address of recipient 1 in theMessage)
-- get rid of stuff after the '@'
set AppleScript's text item delimiters to {"@"}
set senderName to (get first text item of senderName)
set recipientName to (get first text item of recipientName)
-- get rid of anything before leading '<'
set AppleScript's text item delimiters to {"<"}
set senderName to (get last text item of senderName)
set recipientName to (get last text item of recipientName)
--figure out what to use for dest folder
--if sent by user, put in recipient's folder
if senderName is equal to userName then
set folderGuess to recipientName
else
set folderGuess to senderName
end if
-- check to see if mailbox exists
if (mailbox folderGuess of account "Pine Folders") exists then
set theResult to display dialog "Sender:" default answer
folderGuess
else
set theResult to display dialog "Sender:" default answer "????"
end if
set mailbox of theMessage to (mailbox (text returned of theResult)
of account "Pine Folders")
end repeat
end tell