I have looked through the forums for workings on Entourage. This script works for the message which is selected - the displayed message. But what I need is for the script to capture the data from the very latest message in the that entourage folder. ie. the message which has just arrived and i haven’t selected it manually in entourage.
Thus when a new message arrives it will activate the script and send the content of that message ‘elsewhere’
Many thanks
drPETE
tell window 1 of application "Microsoft Entourage"
set m to displayed message
set s to sender of m
set addr to address of s
set dispName to display name of s
set newContent to the content of displayed message
end tell
Here’s an example script for Entourage
part 1 is optional: it connects to your POP/IMAP mailboxes, part2 analyzes your main inbox for unread messages and repeats your desired action on any of them
The command “set unreadlist to messages of inbox folder whose read status = untouched” can paralyse Entourage for a few minutes, therefore it is preceded by a check whether therer a really more messages.
Note: Make sure you don’t have subfolders in your inbox or other folders that get inbound messages by rules or other scripts, that will interfere with this script.
-- part 1
tell application "Microsoft Entourage"
set POPs to every POP account whose (include in send and receive all) is true
set inboxToT to number of messages of inbox folder
if number of items of POPs > 0 then
repeat with acctNum from 1 to count of POPs
connect to (item acctNum of POPs) -- receive mail from each POP account
end repeat
repeat with acctNum from 1 to count of POPs
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
end if
if exists IMAP account 1 then
repeat with acctNum from 1 to count (every IMAP account)
connect to IMAP account acctNum --receive mail from each IMAP account
end repeat
repeat with acctNum from 1 to count (every IMAP account)
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
end if
repeat with acctNum from 1 to count (every POP account)
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
-- part 2
if number of messages of inbox folder > inboxToT then
set MyDisplaySenders to {}
set unreadlist to messages of inbox folder whose read status = untouched
repeat with MessID from 1 to (number of items of unreadlist)
set theMess to item MessID of unreadlist
set mySender to (display name of sender) of theMess
set DisplayMess to mySender
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set newContent to the content of theMess
-- do anything with imaginable newContent
end repeat
end if
end tell
Strange, as far as I know inbox folder has been in Entourage’s dictionary as long as it exists.
You can check that by opening its dictionary in script editor, or reference any given (sub-)folder.
The fewer mails it contains, the faster the script should work.
Check, if it does not recognize inbox folder as an object, any call to a sub-object will go bust.
So if you open MS Entourage in script editor, scroll to “inbox” or “in box” amd use the exact reference in the script, it should work.
You can use that name as long as you reference it right e.g. folder “EVENTS” of inbox folder.
Check that with:
tell application "Microsoft Entourage" to set subnames to name of folders of inbox folder -- or whatever ref your inbox folder needs
I have the same AS version as you have. and am very much in doubt of your Entourage version / completeness.
Open with script editor & read its dictionary /script supplied to see what the inbox folder references exactly are.
If I make a few changes the script runs. It checks my pop accounts according to the chosen send and receive criteria.
After that nothing happens. When I watch Entourage it doesn’t look at the unchecked mail in the “Events” folder.
The event log creates a list of all my folders. Which is encouraging!
regards drPETE
-- part 1
tell application "Microsoft Entourage"
set subnames to name of folders -- or whatever ref your inbox folder needs
set POPs to every POP account whose (include in send and receive all) is true
set inboxToT to number of messages of subnames
if number of items of POPs > 0 then
repeat with acctNum from 1 to count of POPs
connect to (item acctNum of POPs) -- receive mail from each POP account
end repeat
repeat with acctNum from 1 to count of POPs
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
end if
if exists IMAP account 1 then
repeat with acctNum from 1 to count (every IMAP account)
connect to IMAP account acctNum --receive mail from each IMAP account
end repeat
repeat with acctNum from 1 to count (every IMAP account)
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
end if
repeat with acctNum from 1 to count (every POP account)
repeat while connection in progress is true -- waits for mail to download
end repeat
end repeat
-- part 2
if number of messages of subnames > inboxToT then
set MyDisplaySenders to {}
set unreadlist to messages of "EVENTS" whose read status = untouched
repeat with MessID from 1 to (number of items of unreadlist)
set theMess to item MessID of unreadlist
set mySender to (display name of sender) of theMess
set addrNick to address of mySender
set DisplayMess to mySender
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set newContent to the content of theMess
tell application "Address Book"
-- Make new record.
set newPerson to make new person with properties {first name:(word 1 of mySender), last name:(word -1 of mySender), note:"These are " & (word 1 of mySender) & "'s, " & "details:- " & newContent as Unicode text}
save addressbook
end tell
end repeat
end if
end tell
could one use these properties in some combination?
name (Unicode text) : the name of the folder
ID (integer, r/o) : the folder’s unique ID
parent (reference, r/o) : to the folder that contains the folder, or the application if it’s a top level folder
unread message count (integer, r/o) : the number of unread messages in the folder
category (list of reference) : the list of categories
That’s logical: Entourage when supplied just the string “Events” will not interpret that as a reference to a folder.
If you’d refer to folder “Events” instead of “EVENTS” it might, but its location isn’t specified - so it would be a very lucky shot:
set unreadlist to messages of folder "EVENTS" whose read status = untouched
I wouldn’t even try that.
The whole idea of my script is that it works on new messages that - without specific rules or actions - will reside in the inbox folder by default. So there is no way to escape using that as a reference, I am afraid, unless unread messages go into another location that you specify by a rule or script. Which for the moment I wouldn’t suggest you to do.
Therefore my first question was:
What’s the exact reference to the inbox folder that you see when you open Entourage.app in script editor…?
Copy that into the script and it should work…
If those basics do work, you could try using a subfolder like:
set unreadlist to messages of folder "Events" of inbox folder whose read status = untouched
PS. if you mention a Log, please include it in your post!
-- part 2
tell application "Microsoft Entourage"
set subnames to name of folders -- or whatever ref your inbox folder needs
set inboxToT to number of messages of subnames
if number of messages of subnames > inboxToT then
set MyDisplaySenders to {}
--set unreadlist to messages of "events" whose read status = untouched
set unreadlist to messages of folder "events" whose read status = untouched
repeat with MessID from 1 to (number of items of unreadlist)
set theMess to item MessID of unreadlist
set mySender to (display name of sender) of theMess
set addrNick to address of mySender
set DisplayMess to mySender
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set newContent to the content of theMess
tell application "Address Book"
-- Make new record.
set newPerson to make new person with properties {first name:(word 1 of mySender), last name:(word -1 of mySender), note:"These are " & (word 1 of mySender) & "'s, " & "details:- " & newContent as Unicode text}
save addressbook
end tell
end repeat
end if
end tell
gives the following event log
that’s it. It doesn’t play any further.
The problem is that I have a lot of email arriving in the main inbox which has nothing to do with my events project. So I have a rule which acts on the subject of the mail to send it to the “events” folder.
Would a solution be to have the script acting on a specific word in the subject of the mail. Then move it to the “events” folder later?
This works for inbox with no rules. But I had to disable inboxTOT. Also it only acts on the same unread message in the inbox. It doesn’t progress to the next email. Maybe should insert a command to tell entourage that mail read status has been touched. So that on repeat it finds the new untouched mail.
tell application "Microsoft Entourage"
set subnames to name of folders -- or whatever ref your inbox folder needs
set inboxToT to number of messages of subnames
-- if number of messages of subnames > inboxToT then
set MyDisplaySenders to {}
--set unreadlist to messages of "event" whose read status = untouched
set unreadlist to messages of folder "event" whose read status = untouched
repeat with MessID from 1 to (number of items of unreadlist)
set theMess to item MessID of unreadlist
set mySender to (display name of sender) of theMess
--set addrNick to address of mySender
set DisplayMess to mySender
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set newContent to the content of theMess
tell application "Address Book"
-- Make new record.
set newPerson to make new person with properties {first name:(word 1 of mySender), last name:(word -1 of mySender), note:"These are " & (word 1 of mySender) & "'s, " & "details:- " & newContent as Unicode text}
save addressbook
end tell
end repeat
-- end if
end tell
After experimenting with you script. I suddenly thought of another way to do this using the rules in entourage. By making part2 of the script active as the first rule and then using subsequent rules to set the mail as read and move it to the subfolder. Then it always deals with the newest mail.
So now that’s dealt with along comes the next problem. To parse the contents of the mail. A new post.
Many thanks for your help. My knowledge of Applescript is expanding (slowly!). Now I know how to use the event log and result to find out where things are happening.
I can’t help with your specific issue, but if you’re a filter junkie like I am, and are handy with AppleScript, and don’t need IMAP funcionality, MailSmith is definitely worth a look. Of course that was easy for me, since I’m both a BBEdit user (which MailSmith is essentially built on) and I previously used Claris Em@iler (which MailSmith resembles interface-wise in many way).
I’ve never ceased to be amazed by SpamSieve’s (which comes with MailSmith) ability to catch spam, nor the power of GREP and mail filters. And the AppleScript support is, well, wow.
But admittedly, it’s pretty geeky and hardcore for Mac mail software.
We now return you to your regularly scheduled topic…
OK, when your folder “Events” is a subfolder of inbox then the syntax should be
set inboxToT to number of messages of folder "Events" of inbox folder -- instead of subnames
set MyDisplaySenders to {}
set unreadlist to messages of folder "Events" of inbox folder whose read status = untouched -- instead of "event"