I’m having a hard time with the details of a script.
How would I write a script to return the number of unread messages in specified folders of Entourage?
I tried something like this:
set unreadMsgs to unread count of in box folder
but it doesn’t work. Can anyone provide some clues?
Oh, I see… You need the NUMBER of messages…
That code returns a list of unread messages at the in box folder. To know how many items are in this list, simply add “count”:
set msg_number to count (every message of in box folder whose read status is untouched)
Is Applescript able to do something alike? The aim would be for the script to check for unread messages without needing to launch Entourage (if necessary). It would work for a notification when, for example, I come home.
I don’t think this is easily done, so its just a curiosity.
Also, I don’t think this is an easy task… At ancient times there was an osax called “TCP/IP”, and if you learned a little of streams, ports and that stuff, you could do it… Also, I’m pretty sure it does exists any built-in UNIX tool to do this… But I still think that a third-party app will do the job better, such as POPMonitor http://www.macupdate.com/info.php/id/7923, which has options to check mail periodically (or at startup)…
Anyway, you could set up a simple script to open Entourage. Entourage has attached a schedule, which at startup:
will check for new mail
will execute a second script, which
if new mail arrived, post any notification for you
Is there any way to do this with ALL the folders that make up you inbox?
I have a bunch of rules set up to divert incoming emails to different folders in the Inbox. Thing is, Inbox doesn’t show how many messages are in its nesteld folders, it only describes itself.
I tried actually typing in the names of the individual folders that I had set in Entourage but to no avail.
I think you cannot. But you don’t need the name of the folder. Retrieving its ID will be good enough. This chunk of code may return all the hierarchy of your Entourage folders:
build_hierarchy()
on build_hierarchy()
tell application "Microsoft Entourage"
set root_folders to every folder
set folder_names to {}
set folder_ids to {}
repeat with this_folder in root_folders
set folder_names to folder_names & name of this_folder
set folder_ids to folder_ids & (ID of this_folder)
set {f_names, f_ids} to ((return_subfolders into this_folder) of (subfolders of me))
set folder_names to folder_names & f_names
set folder_ids to folder_ids & f_ids
end repeat
end tell
return {folder_names, folder_ids}
end build_hierarchy
script subfolders
property parent : application "Microsoft Entourage"
property f_level : 0
property folder_names : {}
property folder_ids : {}
to return_subfolders into this_folder
if my f_level is 0 then set {folder_names, folder_ids} to {{}, {}}
set thestring to my returnlevel()
try
set all_folders to every «class cFld» of this_folder
repeat with i in all_folders
set folder_names to folder_names & (thestring & i's name)
-- set folder_ids to folder_ids & («class ID » of i)
set folder_ids to folder_ids & (id of i)
my (return_subfolders into i)
set my f_level to (my f_level) - 1
end repeat
end try
set my f_level to 0
return {folder_names, folder_ids}
end return_subfolders
on returnlevel()
set f_level to f_level + 1
set thestring to ""
repeat f_level times
set thestring to (thestring & " ") as text
end repeat
return thestring
end returnlevel
end script
Please, note two things:
:arrow: If you wish only your inbox folder hierarchy, you can substitute the line:
set root_folders to every folder
With this one:
set root_folders to every folder of in box folder
:arrow: To recompile this code, look for this line:
-- set folder_ids to folder_ids & («class ID » of i)
Uncomment it and delete the next one.
This handler may return a list of: a) graphical display of your folder’s hierarchy; b) a list of IDs of such folders.
So, you can use the second list to retrieve the info you need:
set folderIDs to item 2 of build_hierarchy()
set unreadMsgs to {}
tell application "Microsoft Entourage"
repeat with i in folderIDs
set end of unreadMsgs to (every message of folder id i whose read status is untouched)
end repeat
end tell
Now you have unreadMsgs, which is a list of unread messages in form of valid reference, suitable to open, delete, count or whatever task you need.
NumMsgsUnread()
to NumMsgsUnread()
set folderIDs to build_hierarchy()
set unreadMsgs to {}
tell application "Microsoft Entourage"
repeat with i in folderIDs
set unreadMsgs to unreadMsgs & (every message of folder id i whose read status is untouched)
end repeat
end tell
return unreadMsgs's length
end NumMsgsUnread
on build_hierarchy()
tell application "Microsoft Entourage"
set root_folders to every folder of in box folder
set folder_ids to {}
repeat with this_folder in root_folders
set folder_ids to folder_ids & (ID of this_folder)
set f_ids to ((return_subfolders into this_folder) of (subfolders of me))
set folder_ids to folder_ids & f_ids
end repeat
end tell
return folder_ids
end build_hierarchy
script subfolders
property parent : application "Microsoft Entourage"
property f_level : 0
property folder_ids : {}
to return_subfolders into this_folder
if my f_level is 0 then set folder_ids to {}
try
set all_folders to every «class cFld» of this_folder
repeat with i in all_folders
-- set folder_ids to folder_ids & («class ID » of i)
set folder_ids to folder_ids & («class ID » of i)
my (return_subfolders into i)
set my f_level to (my f_level) - 1
end repeat
end try
set my f_level to 0
return folder_ids
end return_subfolders
end script
You are one of those people who can churn this stuff off the top of your head and I hate you.
I was like that, once. But that was mneomic machine code and basic back in the old days. Oh, and I was 16, not 35.
Erm, I’ll give it a go.
This is great though, I’m actually learning something.