Entourage Applescript

Hi there

I am very very new to Applescript having only done a bit of Java before.

I need an Applescript that will show a popup dialog box after an email status is changed to read. For example when I click on it and it is marked as read or when I open it and then close it and it is marked as read.

This script needs to have two options, one button does nothing and the other button needs to forward the email onto a specified email address.

Can anyone help me or advise on this?

Many thanks in advance

Richard

Hello.

I can’t script Entourage, it might happen if it has an “onStatusChanged” event you could hook into for all what I now.

Microsoft use to have very good documentation for its products what concerns AppleScript, I suggest you go to mactopia and search for documentation about what events you can trigger.

Maybe you’ll find on huge pdf book. Having that and reading whats relevant for you, it will be much easier to ask the questions, and get something working.

A solution quickly falling into my mind, is marking and sending in on go as user initiated action. Sparing the obstacles with having to hook into an event.

Best Regards

McUsr

Hi all

I have had a stab at the Applescript and Mail Rule.

The Applescript I have wrote is:

However, I get the error message:

The script encountered error “Microsoft Entourage got an error: Can’t get read status.” during execution.

Does anyone have any idea on where I may have gone wrong?

Many thanks in advance.

Richard

Hello.

I don’t know if this works but you can’t at least use the read property of a message like that.

And you are using the wrong form of quotes to insert the code into your post too! :slight_smile:
Use the “Applescript” button for that! And as said: no guarantees, it might improve the error message however -if any :).


tell application "Microsoft Entourage"
	set theMsg to item 1 of (get current messages)
	tell theMsg
    		repeat while its read status = "untouched"
        		delay 1
    		end repeat
	end tell
	display dialog "Is this message Private or for Traffic?" buttons {"Private", "Traffic"} default button 2
	if answer = "Traffic" then
		forward theMsg to "test@test.com" without opening window
	end if
	if answer = "Private" then
        	set category of theMsg to {category "Personal"}
	end if
end tell


Best Regards

McUsr

Hi

Thanks for this.

The following code partially works:

tell application "Microsoft Entourage"
	set theMsg to item 1 of (get current messages)
	tell theMsg
		repeat while its read status = "untouched"
			delay 1
		end repeat
	end tell
	set question to display dialog "Is this message Private or for Traffic?" buttons {"Private", "Traffic"} default button 2
	set answer to button returned of question
	if answer = "Traffic" then
		forward theMsg to "test@test.com" without opening window
	end if
	if answer = "Private" then
		set category of theMsg to {category "Personal"}
	end if
end tell

but it activates the dialog box upon receipt of the email with no regard if it is read or not. Any ideas?

Thanks

Richard

Hello.

I think you have got both syntax and logic somewhat wrong.
I think the “read” and the “untouched” should be constants, then they should be used without hyphens.
You should actually “instrument” this code to work on the selected message or something similar, when developing the code, and create it as “run” handler or whatever afterwards, after you know that the internals actually works.

Try this, it is untested. -I challenge you to find out how you make this code runnable on a selected message in some inbox of Entourage, and insert log statements into your code, so that you can trace its execution.

tell application "Microsoft Entourage"
	set theMsg to item 1 of (get current messages)
	tell theMsg
		repeat while its read status = untouched
			delay 1
		end repeat
	end tell
	if (get read status of theMsg) is read then
		set question to display dialog "Is this message Private or for Traffic?" buttons {"Private", "Traffic"} default button 2
		set answer to button returned of question
		if answer = "Traffic" then
			forward theMsg to "test@test.com" without opening window
		end if
		if answer = "Private" then
			set category of theMsg to {category "Personal"}
		end if
	end if
end tell

Best Regards

McUsr

Hi

I have a working code:

tell application "Microsoft Entourage"
	set theMsg to item 1 of (get current messages)
	set readstat to read status of theMsg
	repeat while readstat = untouched
		delay 2
		set readstat to read status of theMsg
	end repeat
	set question to display dialog "Is the message 
	Subject: " & the subject of theMsg & "
	From:     " & the display name of the sender of theMsg & "
	Time:     " & the time received of theMsg & "
	Private or for Traffic?" buttons {"Private", "Traffic"} default button 2
	set answer to button returned of question
	if answer = "Traffic" then
		set theMSg2 to redirect theMsg to "test@test.com" without opening window
		send theMSg2
	end if
	if answer = "Private" then
		set category of theMsg to {category "Personal"}
	end if
end tell

However, I have to right click and select Mark as Read. Entourage will not automatically mark it as read and I cannot flag it like I usually could until the Applescript has done it’s thing.

Any ideas?

Richard

Hello.

I went back to edit it, but you were the fastest.

So, have you tried something like this: referring to previous code?


	 ” some more code here ...
	tell theMsg
		set its read status to read
		set its flag state to flag
	end tell
	” some more code here

Hopes this helps, ( its makes for instance the read status to be interpreted as a property of theMsg,
which might help in this case.

Best Regards

McUsr

Sorry I am confused where would I run this code? As my code only comes out of the repeat loop when the status changes to read. Its just Entourage seems to hang when Applescript is assigned to the message ie it wont show it in the preview pane or mark it as read or allow flagging. You have to either right click the message and mark as read or open the email fully and then click mark as read.

Weird?

No, not weird.

You are actually getting what you are begging for.

You ask Entourage to check the status of the mail until the mail is read.
When you somehow have changed the status to read, you get out of that loop.

I hope you see what I mean.

I’m not sure what you are after exactly. Are you running this as a handler for incoming mail that is, which is run when incoming mail arrives ?

Best Regards

McUsr

Hi there

I am running it as a rule on every incoming message.

You’re right this is exactly what I want but usually Entourage would automatically mark a a message as read when you click on it (not double click to open it in a new window) but a click would usually display it in the preview pane.

Unfortunately now the message won’t display and nor will other options like flag etc work until you manually right click the message and mark it as read.

Any ideas?

Sorry if I haven’t explained this right.

Richard

Hello.

Another Idea would be that the on incoming rule that you now are using are collecting the id of the mail and its read status. When it has done that it checks if the status if any if the previous mails in the list has changed, and eventually runs that dialog. This would break the moment you just moved a message in between.

Another approach would be to make a script for setting the read status of the message via a short cut key, and from there run the dialog (and to appropriate actions.)

Edit: It struck me that another approach would be to implement the functionality as a contextual menu item if that is possible via an Automator service, since your workflow is obviously mouse-centric. Automator is really easy to learn, and i think you could pass selected messages within it, that way you could do the same action with just one right click and navigating to the right contextual menu item before you let the mouse free. Performing the same action on all of them.

I think a one click solution alone is impossible. Maybe you could manage it with one click and some modifier key via some shortcut manager. The clue would of course be to make this as a local setting for Entourage, and not obstruct otherwise desired functionality.

Best Regards

McUsr

Hi there

Thank you so much for all your help with this.

I think this option could work but I am a complete newbie on Applescript so am a bit confused how I would store the data? Would I have it collect a list of message IDs and write them to a file. Then maybe every 30mins I have a schedule in Entourage runs a sister Applescript that accesses the IDs from the file and then subsequently runs my dialog method on each one?

Do you mean right clicking on the email to make my script activate? I really need something that pops up to reminds that this choice needs to be made. Thats why I thought my original script was perfect until it started to restrict what Entourage can do!

Many thanks for all your help so far, I feel like I am so close but just not quite there!

Richard

You are quite close.

You just have to stop using the on incoming messages rule or whatever, and write a script which works on selected messages in the understanding that these messages was selected in order to run your script.

Then your script should run through the messages on by one and ask you what you want to do with it, and do the flagging and moving and so on based on your choices.

Thats how I would have attacked the problem. Then I would have tried to see if any shortcut manager would be able
to initiate that script with a click and modifier key combination not already used in Entourage. (using control click for instance wouldn’t be much practical).
If that isn’t possible; honestly - I don’t know if it is but I follow your lead. Then I’d have a look at automator and see if there were some Entourage action there, working with or returning selected messages, and then have that action pass the messages to an applescript action, where your script which work on messages should be pasted in, then you could assign a shortcut to it from the services menu, and have access to the script from the contextual menu when you right click on the selected messages. You could of course put your script in the Entourage script menu as well. And invoke it after you have selected the messages.

I’m just trying to give you some practical options here.

Best Regards

McUsr