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 Search Today's Posts Mark Forums Read

 
OF Task to Mail Thread Tools Search this Thread Display Modes
Hello,

I searched the forums but couldn't find what I was looking for:
Is there a script that will take the selected task in OF and create an email message with the subject of that task and maybe any attachments that it might have?

Can somebody help with this?

The reason I ask for it is that I have lots of tasks that I delegate via email to other people. Now I work in this way:I createad a context for each people and now I send a pdf with all these tasks
Thanks
 
Hi Mushudog,

I'm a beginner with applescript but managed to hack together a script for you.

The scipt is largely based on the complete and awaiting reply script by Curt Clifton.

Curt Clifton graciously allowed me to post this modified script which I hope meets your needs.

Regards,

Jhn

Code:
(*

This script will take the currently selected action in OmniFocus and send it to mail, completing that action in OmniFocus and create a new "waiting for action".

The context, action prefix and suffix can be changed by changing the waitingForContext, WaitingPrefix and WaitingSuffix properties respectively.

Script by jhncbrwn (c) 2009

Based on an original script copyright  2007-2008, Curtis Clifton


	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*)

--Here you can assign the context, the prefix and suffix
property waitingForContext : "wf"
property waitingPrefix : "Waiting for: "
property WaitingSuffix : "Delegated"

--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 dd & "/" & mm & "/" & yy as string

--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

--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
 
dear Jhn,

Thank you for your time. I tried to run the script but I get an error:
Can't get item 1 of {}.
 
You need to create a 'Waiting for' context or edit the script to work with your existing waiting context.

@jhncbrwn (and Curt), nice work! I think this will be a useful script for me.
 
Indeed- works!
It is the most useful script I have!
Thank you all for this!
 
This script is great! I was thinking for some tweaking if somebody will be willing to do it. For example in the Waiting for context I have other subcontexts for people That I delegate to:
Waiting for: ->George
Waiting for: -> Mary and so on.

It would be great if after running the script a popup window will appear and ask you to select the person you delegate to (from the waiting for context) (the idea came after installing this script here: http://forums.omnigroup.com/showthread.php?t=12541 )
 
@jhncbrwn...thanks for the great script. I'm impressed with your "beginner" "hack" of a script. If this is what you do as a beginner, I'd be curious to see your expert scripts! I don't even know where to start with AppleScript.

I have some feature requests for your script. Another OF user built a script that sent a task to Inbox w/ a "Waiting For" context...it had two features I'd love to see in your script.
1. It placed the url "link-back" to the sent email into the note field of the action it produced in OF. This is very nice for being able to track my "delegation."
2. It produced a Growl notification (if Growl was installed) notifying of the action being produced in OF...which is reassuring to OCD people like myself

I'm not sure if the url link-back feature is possible in your script, because the OF -> email is opposite the email -> OF direction of his script. But like I said...I have no idea of AppleScripts abilities.

Here are the links to his OF forum post and his blog:
http://forums.omnigroup.com/showthread.php?t=12810
http://www.simplicityisbliss.com/200...y-applescript/

Code:
(*
	Waiting For Mails to OmniFocus Script
	by simplicityisbliss.com, Sven Fechner
	
	Based on an Outbox Rule in Mail.app this script adds specific messages
	to the OmniFocus Inbox with the waiting for context
	
	MailTags (www.indev.ca) is required to define the Outbox Rule to only
	create tasks for those outgoing emails that are to be tracked in OmniFocus
	
	The script uses Growl for feedback notification if it is installed and running
	
*)


--!! EDIT THE PROPERTIES BELOW TO MEET YOUR NEEDS !!--

-- Do you want the actualy mail body to be added to the notes section of the OmniFocus task?
-- Set to 'true' is or 'false' if no
property mailBody : true

-- Text between mail recipient (the person you are waiting for to come back) and the email subject
property MidFix : "to follow up re:"

-- Name of your Waiting For context in OmniFocus
property myWFContext : "Waiting For"

-- !! STOP EDITING HERE IF NOT FAMILAR WITH APPLESCRIPT !! --

--Configuration for Growl messages 
property GrowlRun : false
property scriptName : "Waiting For Mails to OmniFocus"
property notifySuccess : "Success Notification"
property notifyFail : "Failed Notification"
property titleSuccess : "Waiting For Mail added"
property titleFail : "Waiting For Mail to OmniFocus FAILED"
property txtSuccess : " added to OmniFocus successfully"
property txtFail : " to OmniFocus to add successfully"
property txtIcon : "OmniFocus"

on perform_mail_action(theData)
	
	--Check if Growl is running
	tell application "System Events" to set GrowlRun to (count of (every process whose name is "GrowlHelperApp")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "GrowlHelperApp" to register as application scriptName all notifications {notifySuccess, notifyFail} default notifications {notifySuccess, notifyFail} icon of application txtIcon
	
	--Get going
	tell application "Mail"
		set theMessages to |SelectedMessages| of theData --Extract the messages from the rule
		repeat with theMessage in theMessages
			set theSubject to subject of theMessage
			set theRecipient to name of to recipient of theMessage
			set theMessageID to urlencode(the message id of theMessage) of me
			
			-- Check if there is one or more recipients
			if (count of theRecipient) > 1 then
				set theRecipientName to (item 1 of theRecipient & (ASCII character 202) & "and" & (ASCII character 202) & ((count of theRecipient) - 1) as string) & (ASCII character 202) & "more"
			else
				set theRecipientName to item 1 of theRecipient
			end if
			
			set theTaskTitel to theRecipientName & (ASCII character 202) & MidFix & (ASCII character 202) & theSubject
			set messageURL to "Created from message://%3C" & (theMessageID) & "%3E"
			set theBody to messageURL
			if mailBody then set theBody to theBody & return & return & the content of theMessage
			
			-- Add waiting for context task to OmniFocus
			tell application "OmniFocus"
				tell default document
					set theContext to context myWFContext
					make new inbox task with properties {name:theTaskTitel, note:theBody, context:theContext}
				end tell
			end tell
			my GrowlSuccess("Mail: " & theSubject)
		end repeat
	end tell
	
end perform_mail_action

on GrowlSuccess(theMessage)
	if GrowlRun then tell application "GrowlHelperApp" to notify with name notifySuccess title titleSuccess description theMessage & txtSuccess application name scriptName
end GrowlSuccess

on urlencode(theText)
	set theTextEnc to ""
	repeat with eachChar in characters of theText
		set useChar to eachChar
		set eachCharNum to ASCII number of eachChar
		if eachCharNum = 32 then
			set useChar to "+"
		else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
			set firstDig to round (eachCharNum / 16) rounding down
			set secondDig to eachCharNum mod 16
			if firstDig > 9 then
				set aNum to firstDig + 55
				set firstDig to ASCII character aNum
			end if
			if secondDig > 9 then
				set aNum to secondDig + 55
				set secondDig to ASCII character aNum
			end if
			set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
			set useChar to numHex
		end if
		set theTextEnc to theTextEnc & useChar as string
	end repeat
	return theTextEnc
end urlencode
Obviously your script is awesome as it is...these are just two features I would personally add if I had the knowledge. If somebody else would give it a whirl...I'd be very appreciative.

Cheers...Brett

Last edited by bpwhistler; 2009-08-17 at 10:50 AM..
 
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
 
Hi,

is it be possible to amend this script to email the user with a list of all tasks due that day or is it a start from scratch job- I'm trying to replicate Toodledo's excellent functionality in this area.

Many thanks



Nick
 
Another possible approach would be to make a perspective that shows the tasks you want included in the email, call it "Tasks due today" or whatever suits you. This perspective can be opened by visiting the URL omnifocus:///perspective/Tasks%20due%20today and there's support in iCal to run scripts as an alarm. With a bit of tinkering, I think you could have iCal run a script that opens that perspective, uses UI scripting to issue a print command to print to a PDF file that gets handed to Mail and sent to you. You might not have to learn as much about Applescript to go this route, although that's just an off the cuff guess.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I forward a E-Mail to Omni and you make it a task? Librerio Applying OmniFocus 1 2011-10-30 01:37 AM
New task from Mail attachment only? RFBriggs OmniFocus 1 for Mac 9 2010-06-02 01:19 PM
Send task as e-mail Arild OmniFocus Extras 1 2010-03-09 02:44 AM
Omnifocus task/action to Apple Mail gandalf44 OmniFocus Extras 1 2009-05-27 12:53 PM
Creating Task from E-Mail? tango OmniFocus 1 for Mac 1 2007-06-29 02:17 PM


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


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