The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Today's Posts

 
New Script - Selected Entourage EMail to Selected OF Task Thread Tools Search this Thread Display Modes
New script for you... this:
- takes the selected email, or the currently open email
- either attaches it to the currently selected OF task
- or opens QuickEntry with the message details to make a new task.

For instance -

- Select the task "Tell John to go fly a kite"
- Write an email to John telling him to go fly a kite
or
- Click the email where you told John to go fly a kite
- Run script (before clicking "send") from Entourage Scripts menu
- Your task now has the email attached where you acted on it and told John

Hope it's of use to everyone. Great way to see *where* you acted on the task, rather than just checking it "Complete" to indicate that you *did* act on it.

Cheers,
David.

Code:
-- This script takes the selected email in Entourage, or the currently-open email,
-- and either attaches a note with the embeded file link to the currently selected OF task,
-- or opens QuickEntry populated with the contents of the email (if no task is selected).

-- Released to the Public Domain
-- (c) David Szego david.szego@me.com Feb. 12 2009 
-- Happy 3rd birthday, Isaac!

tell application "Microsoft Entourage"
	
	if the class of the front window is message window then
		set theMessage to the displayed message of the front window
		-- Get the message details
		set messageDetails to my ProcessMessage(theMessage)
		set theMDfile to item 1 of messageDetails
		set theTitle to item 2 of messageDetails
		set theSender to item 3 of messageDetails
		set theContent to item 4 of messageDetails
		-- Attach it to task in OF, or make a new task
		my attachToOF(theMDfile, theTitle, theSender, theContent)
	else if the class of the front window is draft window then
		save the front window
		set theMessage to the displayed message of the front window
		-- Get the message details
		set messageDetails to my ProcessMessage(theMessage)
		set theMDfile to item 1 of messageDetails
		set theTitle to item 2 of messageDetails
		set theSender to item 3 of messageDetails
		set theContent to item 4 of messageDetails
		-- Attach it to task in OF, or make a new task
		my attachToOF(theMDfile, theTitle, theSender, theContent)
	else
		set theSelection to the selection
		set handledMessage to false
		set msgCount to 0
		repeat with theMessage in theSelection
			if the class of theMessage is incoming message or ¬
				the class of theMessage is outgoing message then
				-- Get the message details
				set messageDetails to my ProcessMessage(theMessage)
				set theMDfile to item 1 of messageDetails
				set theTitle to item 2 of messageDetails
				set theSender to item 3 of messageDetails
				set theContent to item 4 of messageDetails
				-- Attach it to task in OF, or make a new task
				my attachToOF(theMDfile, theTitle, theSender, theContent)
				set handledMessage to true
				set msgCount to msgCount + 1
			else
				display dialog "Skipping message " & subject of theMessage
			end if
		end repeat
		if handledMessage = false then
			display dialog "You need to select at least one email or news message " & ¬
				"in order to use this script." with icon 2 buttons {"OK"} default button "OK"
		end if
	end if
	
end tell


on ProcessMessage(theMessage)
	
	using terms from application "Microsoft Entourage"
		set theTitle to subject of theMessage
		set theSender to display name of sender of theMessage
		set theContent to content of theMessage
		set theID to ID of theMessage as string
		
		-- Get the message path for attachment in OF
		set theCommand to "mdfind com_microsoft_entourage_recordID==" & theID
		set theMDfile to the first item of paragraphs of (do shell script theCommand)
		
		return {theMDfile, theTitle, theSender, theContent}
		
	end using terms from
	
end ProcessMessage

on attachToOF(theMDfile, theTitle, theSender, theContent)
	
	tell application "OmniFocus"
		tell front document
			
			-- Get the first selected task
			tell (first document window whose index is 1)
				set selectedTasks to selected trees of content
				
				-- If no task is selected, open a quick-entry					
				set numItems to (count items of selectedTasks)
				if numItems is 0 then
					tell application "OmniFocus"
						tell quick entry
							set theName to theSender & ": " & theTitle
							set NewTask to make new inbox task with properties {name:theName, note:theContent}
							-- Add a link to the note of the new task
							tell the note of NewTask
								make new file attachment with properties {file name:theMDfile, embedded:false}
							end tell
							--
							activate
						end tell
					end tell
					--	
					
				else
					
					-- Get the selected task
					set selectedTask to value of item 1 of selectedTasks
					set selectedTaskc to item 1 of selectedTasks
					-- Add a link to the note of the selected task
					tell the note of selectedTask
						make new file attachment with properties {file name:theMDfile, embedded:false}
					end tell
				end if
				
			end tell
		end tell
	end tell
	
end attachToOF
 
Thank you for your script.

I am trying to use it with Entourage 2004. Have you tried it with this version?

I have a error with the line:

set selectedTasks to selected trees of content

The error seems to be related to index 1 of OmniFocus. Can you give some explanation bout this?

Thank you.
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to re-order selected items by start date barrettj OmniFocus Extras 2 2013-04-11 07:34 AM
Script: Schedule selected items for this weekend dbyler OmniFocus Extras 1 2011-07-06 05:52 AM
Script to copy columns (and any selected rows) to new doc RobTrew OmniOutliner 3 for Mac 0 2010-06-07 03:47 AM
Wanted: Send Selected Contexts to Email steve OmniFocus Extras 9 2007-12-08 07:35 AM
Get selected tasks with script? curt.clifton OmniFocus 1 for Mac 1 2007-06-10 06:43 PM


All times are GMT -8. The time now is 04:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.