Thread: OF Task to Mail
View Single Post
I hacked together a few changes...and came up with a script based on jhncbrwn's OF "Task to Email" script and the original "Complete and Await Reply" script by Curt Clifton that jhncbrwn mentioned.

I changed a few of the text notifications to suit my need, and depending on how you look at it added a feature to the scripts:
-I either added email notification to Curt's script...or
-added Growl notification to jhncbrwn's script.

I'm still interested in seeing if a link-back to the email sent can be added to the notes field of the waiting-for action that is generated. I've been unable to cobble one together...but my scripting skills are purely plagiaristic.

Here is my version of the script...based on Curt Clifton's and jhncbrwn's scripts:

HTML Code:
(*
	This script marks the selected actions as complete and creates new actions in a "Waiting For" context to track replies.
	
	version 0.1, by Curt Clifton
	
	Copyright © 2007-2008, Curtis Clifton
	
	All rights reserved.
	
	Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
	
		• Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
		
		• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
		
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	
	version 0.1: Original release
*)

(*
	This string is matched against your contexts to find a context in which to place the new "waiting-for" action.  The matching is the same as in the context column in OmniFocus, so you don't need the entire contexxt name, just a unique fragment.
*)
property waitingForContext : "wait"

(*
	This string is used as a prefix on the original item title when creating the "waiting-for" action.
*)
property waitingPrefix : "Waiting for: "
property WaitingSuffix : "Emailed:"


--This configures the date
set dateX to (current date) + (0 * days)
set A to ((month of dateX as number) + 100) as string
set b to ((day of dateX) + 100) as string
set c to ((year of dateX) + 100) as string

tell A
	text 2 thru 3
end tell
set mm to result

tell b
	text 2 thru 3
end tell
set dd to result

tell c
	text 3 thru 4
end tell
set yy to result

set Current_date to mm & "/" & dd & "/" & yy as string

(*
	The following properties are used for script notification via Growl.
*)
property growlAppName : "Curt's Scripts"
property scriptStartNotification : "Script Began"
property scriptFinishNotification : "Script Completed"
property defaultNotifications : {scriptFinishNotification}
property allNotifications : defaultNotifications & {scriptStartNotification}
property iconLoaningApplication : "OmniFocus.app"

--This creates the new action
set itemTitle to missing value
tell application "OmniFocus"
	tell front document
		-- Gets target context
		set theContextID to id of item 1 of (complete waitingForContext as context)
		set theWaitingForContext to first context whose id is theContextID
		tell content of document window 1 -- (first document window whose index is 1)
			set theSelectedItems to value of every selected tree
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select an item to complete." as warning
				return
			end if
			repeat with anItem in theSelectedItems
				set itemTitle to name of anItem
				set theDupe to duplicate anItem to after anItem
				set completed of anItem to true
				set theNote to note of anItem
				
				-- Configure the duplicate item
				set oldName to name of theDupe
				set name of theDupe to waitingPrefix & oldName & " (" & WaitingSuffix & " " & Current_date & ")"
				set context of theDupe to theWaitingForContext
				set repetition of theDupe to missing value
			end repeat
		end tell
	end tell
end tell
if itemTitle is not missing value then
	my notify("Completed and Awaiting Reply", itemTitle, scriptFinishNotification)
end if

--This sends all of it to mail
tell application "Mail"
	set accountAddresses to (email addresses of first account)
	set fromAddress to first item of accountAddresses
	set theMessage to make new outgoing message
	set visible of theMessage to true
	set subject of theMessage to oldName
	set content of theMessage to theNote
	activate
end tell

(*
	Uses Growl to display a notification message.
	theTitle – a string giving the notification title
	theDescription – a string describing the notification event
	theNotificationKind – a string giving the notification kind (must be an element of allNotifications)
*)
on notify(theTitle, theDescription, theNotificationKind)
	tell application "GrowlHelperApp"
		register as application growlAppName all notifications allNotifications default notifications defaultNotifications icon of application iconLoaningApplication
		notify with name theNotificationKind title theTitle application name growlAppName description theDescription
	end tell
end notify