Help with Entourage X script

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?

You can really ever compile this sentence?
Try this instead:

set x to every message of in box folder whose read status is untouched

Thanks for the tip.

This is the script right now:

try
tell application “Microsoft Entourage”
activate
delay 5
set msg_number to every message of in box folder whose read status is untouched

set msg_text to msg_number as string
return {“test”, msg_text}
end tell
on error
return {“test:”, “sorry.”}
end try

Doesn’t seem to work. Sorry, I’m extremely new at this and don’t really know where to go from here.

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)

Thank you. This works wonderfully now.

Here is a question on the capabilities of Applescript:
MobileSync http://homepage.mac.com/jonassalling/Shareware/MobileSync/index.html is able to sync my T68i with Entourage addresses without needing to launch Entourage. Somehow it accesses the database on its own.

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
    • quits Entourage again

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.

Any idea?

You can access any object hierarchically:

tell application "Microsoft Entourage"
	folder "kk" of folder "pp" of in box folder
end tell

Will call:

-Inbox
  -kk
    -pp <<--
- Outbox
- ...

Is there a way of saying something like

return unread message count of all folders of folder inbox

without having to name and add up all the embedded folders?

Or would I have to make a loop to count through them all

I don’t want to have to keep adding folders to my script each time I create new ones in Entourage

thanks

bev

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.

(Hope html hasn’t mangled the code :twisted: )

function queryMail() {
return appleScript(‘tell application "Microsoft Entourage"n return unread message count of folder "Inbox"n end telln’);
}

This is it so far as the code goes, being called from Konfabulator to make a simple widget show how many messages in your inbox.

How would I incorporate your code into this?

Sorry, haven’t done this for years, scratchy!

Hmmm…

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

After substitute CR for “n”, this may do the job.

You are one of those people who can churn this stuff off the top of your head and I hate you. :wink:
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.

I’ll get back to you.