Outlook notifications in Notification Center using AppleScript

I’m familiar with a few programming languages but AppleScript is new to me (and it looks pretty powerful and useful, makes me wonder why I didn’t learn it before…).

I recently learned of the existence of an app called “Notification Scriptings” ( http://www.cooperative-fruitiere.com/notifications/index_en.html ) that lets you create custom Notification Center notifications using AppleScript.

So I looked at Outlook’s dictionary to see what I could do and with a rule set in Outlook 2011 to execute my script every time an email comes in, I can get notifications for every message.

My only problem, is what happens when you click the notification…

The “Message” object seems to be temporary so the only way I can store something long term is by storing the message in the user info argument, I think…

So, here’s my script. It shows notifications (also I made a custom copy of Notifications Scriptings and copied Outlook’s icon in it so everything looks native


property theMessages : null
tell application "Notifications Scripting"
	set subtitle to ""
	set thebody to ""
	--  This is required for calling the user notification event handlers. The handlers can be in a different script file.
	set event handlers script path to (path to me)
	
	-- The user info parameter is a record. The supported data types are text, integer, real, boolean, date, alias, file and POSIX file.
	set dict to {theName:"Notifications Scripting", theVersion:"1.0", theScript:event handlers script path}
	
	-- Create a notification. Only the title is required at minimum.
	-- Use "Default" for the default sound played by the user notification center.
	-- See the Notifications Scripting dictionnary for more informations.
	tell application "Microsoft Outlook"
		set theMessages to current messages
	end tell
	
	set theMessageCount to count theMessages
	
	tell application "Microsoft Outlook"
		repeat with a from 1 to 1
			tell item a of theMessages
				set theSubtitle to subject
				set thebody to plain text content as string
				
			end tell
			
			--open item a of theMessages
			
		end repeat
	end tell
	--set theThing to {Message:item 1 of theMessages, number:2}
	display notification "Outlook" subtitle theSubtitle message thebody sound name "Default" --user info theThing
end tell


using terms from application "Notifications Scripting"
	
	-- This handler is called when a notification was delivered.
	-- All parameters are optionnals.
	on notification delivered title aTitle subtitle aSubTitle message aMessage actual delivery date aDeliveryDate user info aDict
		
		tell application "Finder"
			
			--display dialog aTitle & return & aDeliveryDate & return & (theScript of aDict) as text
			
		end tell
		
	end notification delivered
	
	
	-- This handler is called when a notification was activated.
	-- All parameters are optionnals.
	on notification activated title aTitle subtitle aSubTitle message aMessage delivered date aDeliveryDate activation type aType user info theMessageThing
		
		tell application "Microsoft Outlook" to activate
		
		
	end notification activated
	
end using terms from



It’s working fine but redirecting to the right message would make that script act just like a native Outlook Notification Center integration might look like…

How could I tell outlook to open the right message?
Is it even possible?

Thanks

EDIT: Yes the names of my variables are absolutely awful. I am aware of that…

Browser: Safari 536.30.1
Operating System: Mac OS X (10.8)

Hi lap.felix,

Is your question about scripting Outlook or about the user info in Notifications scripting? Note that the example supplied script shows an example about the user info (record). Maybe the question is about records?

gl,
kel

Hello Kel,

The question is how I can use the user info in Notifications scripting (which is storing records, exactly) to open a specific message in Outlook when I press on the notification of that message.

But the thing is, Outlook only opens message files, so I can’t open a message by its title or anything else…

Thanks,

Felix

Hi,

I don’t have Outlook, but you need something unique like a string or numeric identifier.
You can’t pass the message object, because the user info record is limited to string, number, data and date types (beside lists and records).

get the unique identifier in the tell item a of theMessages block and pass it as a record.

In the on notification activated handler read the identifier from the record (theMessageThing) and get the message in Outlook

That’s the first thing I thought of doing, but after reading Outlook’s dictionary, it doesn’t seem like there’s a way to open a message in Outlook based on an identifier…

Is there an id property in class message ?
If yes, this is the identifier