Outlook 2011 Script for Omni Focus 2

Does anyone know if there is a new script to take an email from Outlook 2011 and put it in the inbox of OF2?

Thanks!

1 Like

I’m using the same AppleScript for OF1 that a co-worker gave me a couple years ago, and it works fine. I’m using Outlook 2011 14.4.1. I’ll send you a private message with a Dropbox link to the script I’m using.

Out of curiosity, why do you use a script like this rather than just emailing to your OF2 inbox? (I’m wondering which one I should use)

I use the script instead of the mail drop feature so that I can make sure the task get’s in the right project and context right off the bat. I use mail drop with my iphone/ipad.

Here’s the script I’d been using with OF1, which was originally created by Rainer Burgstaller for Entourage, i believe:

tell application "Microsoft Outlook"
	
	-- get the currently selected message or messages
	set selectedMessages to current messages
	
	-- if there are no messages selected, warn the user and then quit
	if selectedMessages is {} then
		display dialog "Please select one or more messages first and then run this script." with icon 1
		return
	end if
	
	repeat with theMessage in selectedMessages
		
		set theName to subject of theMessage
		set theContent to content of theMessage
		set theID to id of theMessage as string
		
		-- set the path to a temp area on your HD to temporarily store the attachment to be loaded into OF
		set theFileName to "/tmp/entourage" & theID & ".eml"
		set theOutFileName to "/tmp/outlook-" & theID & ".txt"
		tell application "OmniFocus"
			log "saving the file" & theFileName
			log "out filename " & theOutFileName
		end tell
		save theMessage in theFileName
		set homeFolder to (path to home folder as text)
		set posixHome to (POSIX path of homeFolder)
		--		set theTxtContent to do shell script "\"" & posixHome & "/Documents/Microsoft User Data/Outlook Script Menu Items\"/decoder < " & theFileName
		do shell script "java -jar \"" & posixHome & "/Documents/Microsoft User Data/Outlook Script Menu Items\"/MailDecoder.jar " & theFileName & " " & theOutFileName
		
		tell application "Finder"
			set foo to (open for access (theOutFileName))
			set theTxtContent to (read foo for (get eof foo) as «class utf8»)
			close access foo
		end tell
		
		--set theTxtContent to (contents of theOutFile)
		tell application "OmniFocus"
			set theDoc to default document
			set theTask to theName
			set theNote to theTxtContent
			tell quick entry
				open
				set NewTask to make new inbox task with properties {name:theTask, note:theTxtContent}
				tell the note of NewTask
					make new file attachment with properties {file name:theFileName, embedded:true}
				end tell
				activate
			end tell
		end tell
		
		-- Only Uncomment if you really understand and are happy with the process and want the message to 
		-- be removed from Entourage after it gets sent to OF
		
		-- delete theMessage		
	end repeat
end tell

-- bring OmniFocus to the front
-- thanks to tim @ omni for this one
tell application "OmniFocus"
	--activate
	tell first document window of front document
		set «class FCvm» to "project"
		tell sidebar
			«event OTREisal» «class FCIb»
		end tell
	end tell
end tell
-- delete all the old leftover emails
do shell script "rm /tmp/entourage*.eml /tmp/outlook*.txt"

The script was brilliant, in that it created a new item in the quick entry window, with the email subject as the task name, the body of the email in notes, and crucially, a link back to the original message at the bottom of the notes section, which could be double-clicked to open the original message and begin typing a response. Unfortunately, it’s no longer working completely with OF2. The message is still created in the quick entry window, with the body in the notes, but the link back to the original message is lost, and Outlook throws an error that says,“Omnifocus got an error. Unable to read file from '/temp/entourage127147.eml”

I know nothing about Applescript, so if anyone here knows how to tweak the above to solve this problem, I (and I’m sure others) would be very appreciative!

I use a script instead of mail drop because of corporate confidentiality.

1 Like

When scripting a sandboxed app, you need to reference files in a way that tells AppleScript they’re files rather than just sending along a file path. (Otherwise, the sandboxing system doesn’t know that the target app should be granted access to that file.)

In this case, I think that means you’d need to change this line:

make new file attachment with properties {file name:theFileName, embedded:true}

to say this:

make new file attachment with properties {file name:POSIX file theFileName, embedded:true}

Hope this helps!

Ken, you rock; that got the attachment back, thanks!

I was still getting the outlook error message, and I noticed when I tried to compile the script, I was getting a syntax error in the Applescript Editor that said, “Can’t set «class FCvm» to “project”. Access not allowed.” As such, I pulled out everything starting with the “Bring Omnifocus to front” comment, and that got rid of the error message in Outlook and allowed me to compile the script in the Applescript Editor.

one more question - with the revision you suggested above, I now get an action where the notes field starts with the attachment, followed immediately by the body of the message, with no space between the two. On OF1, what happened with the original script was that the body of the messages was first, followed by the attachment, set apart a bit from the text. That was nice in that you could review the message, formulate a plan for response, and then double click the attachment at the bottom to execute that response. Any suggestion for a further tweak to the script to replicate that placement, with the attachment at the bottom of the note, set apart from the body text?

Thanks again!

Adam

1 Like

Codog24, I’m running into the same outlook error message. I’ve tried replacing project to inbox and a couple other places that the info might go but to no avail.

Can anyone point me in the right direction to understanding what <> represents? I think that’s the issue?

Hey Everyone – Just updated my own Outlook to OmniFocus AppleScript to work with OF2 and I could use some help running down an issue with attachments.

Basically, some (but, interestingly, not all) users are reporting errors when transferring items with attachments. As published, the script references files with an alias, thus:

tell application "OmniFocus"
        tell the note of NewTask
	make new file attachment with properties {file name:theFileName as alias, embedded:true}
end tell

This works on my system and others also report success. For the people who have reported problems, I have sent them test builds with the “file” and “POSIX file” formulation, à la:

make new file attachment with properties {file name:file theFileName, embedded:true}

or

make new file attachment with properties {file name: POSIX file theFileName, embedded:true}

Nothing seems to work for them, though… and I’ve confirmed that they’re running OF2 Pro and the latest OS X/Outlook builds.

Any ideas?

Justin Lancy
Veritrope

1 Like

This is working for me (with emails with or without attachments) well, but is there a way to attach the .eml file for the email to the omnifocus task so we can quickly open that email and process it as necessary (archive, forward, reply, etc.).

Thanks!

EDIT: Has anyone had any luck with finding how to add the email as an attachment (like .eml) instead of including all the text from the email?

Probably won’t have time to work on the script again for a little while, but I’ll definitely look at adding this as a feature for the next revision!

-Justin

1 Like

I was playing with Veritrope’s awesome script to add the context of “Waiting” (I would use a different hot key for this script than just the normal adding to Omnifocus). Context doesn’t seem to be an available property for a new project task or new inbox task. The script will complete, and the task will appear in Omnifocus under the right project with the right context, but the task doesn’t seem “valid” – it is grayed out and doesn’t appear in the Context view. Here’s the script:

tell theProject to make new task with properties {name:OFTitle, context:theContext, note:theContent, flagged:theFlag, due date:theDueDate, completion date:theCompletionDate, defer date:theStartDate}

When I compile it, the word “context” appears in blue, unlike all the other properties which appear in purple.

Anybody have any suggestions? Thanks so much for any help!

Someone who seems to be using your script contacted us about not being able to open .eml files. Do you know if that’s the same file type your other users are unable to open? Or has it been a variety?

@lizard Feel free to put the user in touch with me directly, but the few issues I’ve seen so far turned out to be other things (one went away after a system restart, another had an older version of the script, and other was a person who didn’t realize they needed Pro to run AppleScript!).

1 Like

@Veritrope I take that back. The one who contacted us is not, after all, using your script. I apologize for the confusion.

No problem!

FYI– There was also a script going around which creates a link to the Outlook item via a Custom URI scheme that I’ve heard isn’t working right now. (I chose not to take that approach because it isn’t from Outlook’s AppleScript dictionary and so I thought it might be a pain to maintain)

1 Like

@Veritrope Awesome script… !! Is there a way I can modify it such that the link to the original email is retained in the notes ? My use case will be to click on the link itself to reply to that email instead of going back in Outlook to hunt for that message…

Any help will be really appreciated !

Thanks,
Pash

2 Likes

+1 for Pash’s suggestion - would be really useful to have the link to the original email in Outlook appear in the notes field of an OF 2 task.

1 Like

Hey @pashmeen and @jpodcaster – There’s currently no way to do this with Outlook’s AppleScript dictionary, but I reached out to a contact at Microsoft to ask if it could be included in a future release. His response was favorable.

If and when this gets added to Outlook, I’ll be sure to add it to the script! :-)