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 1 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Attachments and Mail Integration Thread Tools Search this Thread Display Modes
I'd like very much to be able to forward an email with a document I need to review to myself and have both the email and the attached document show up in OmniFocus... I just tried this and it didn't work, is this a bug or feature request?

-- Bindu
 
More specifically the text of the email shows up in OmniFocus, but the attachment did not.
 
I would second this request.
 
I looked at the applescript for the mail integration. It looks like I can get the attachments from Mail.app but don't see anyway to add them to the task(s) created in OmniFocus via applescript... Anyone know how to add a file to a Task via Applescript?
 
You can use the attachment element of the rich text class to add attachments to the note of a task programmatically. For more information, this thread on the OmniFocus Extras forum seems useful. (In general, more scripting discussion happens on the Extras forum.)
__________________
Cheers,

Curt
 
Sweet, I'll see if I can get the default applescript updated, thanks!
 
This is my first real attempt at applescript so I'm sure there are plenty of places it could be improved (like the fact that I'm hard coding the disk and temp directory names and not handling there being naming conflicts in the temp directory.) So your mileage may vary...

Code:
-- Copyright 2007 The Omni Group.  All rights reserved.
-- Hacks by Bindu Wavell <bindu@wavell.net> allow for attachments to be processed
--
-- $Header: svn+ssh://source.omnigroup.com/Source/svn/Omni/branches/OmniFocus/1.x/OmniGroup/Applications/Focus/App/Preferences/MailAction.applescript 100519 2008-05-15 21:12:32Z bungi $

using terms from application "Mail"
	
	--used the following while debugging to trigger script execution
	--tell application "Mail"
	--	set theSelectedMessages to selection
	--	set theSelectedMessage to the first item in theSelectedMessages
	--end tell
	--process_message(theSelectedMessage)
	
	on write_error_log(this_error)
		set the error_log to ((path to desktop) as text) & "Script Error Log.log"
		try
			open for access file the error_log with write permission
			write (this_error & return) to file the error_log starting at eof
			close access file the error_log
		on error
			try
				close access file the error_log
			end try
		end try
	end write_error_log
	
	-- Trims "foo <foo@bar.com>" down to "foo@bar.com"
	on trim_address(theAddress)
		try
			set AppleScript's text item delimiters to "<"
			set WithoutPrefix to item 2 of theAddress's text items
			set AppleScript's text item delimiters to ">"
			set MyResult to item 1 of WithoutPrefix's text items
		on error
			set MyResult to theAddress
		end try
		set AppleScript's text item delimiters to {""} --> restore delimiters to default value
		return MyResult
	end trim_address
	
	
	on process_message(theMessage)
		tell application "OmniFocus"
			log "OmniFocus calling process_message in MailAction script"
		end tell
		-- Allow the user to type in the full sender address in case our trimming logic doesn't handle the address they are using.
		set theSender to sender of theMessage
		set trimmedSender to my trim_address(theSender)
		tell application "OmniFocus"
			set AllowedSender to allowed mail senders
			if AllowedSender does not contain trimmedSender and AllowedSender does not contain theSender then
				return
			end if
		end tell
		
		set theAttachments to mail attachments of the theMessage
		set theAttachmentCount to count of theAttachments
		
		set theSubject to subject of theMessage
		set singleTask to false
		if (theSubject starts with "Fwd: ") then
			-- Whole forwarded messages shouldn't split.
			set singleTask to true
			set theSubject to text 6 through -1 of theSubject
		end if
		set theText to theSubject & return & content of theMessage
		tell application "OmniFocus"
			tell default document
				set theTasks to parse tasks with transport text theText as single task singleTask
			end tell
		end tell
		
		set theTaskCount to the count of theTasks
		if theTaskCount > 0 and theAttachmentCount > 0 then
			set theTask to the first item in theTasks
			
			repeat with theAttachmentIndex from 1 to theAttachmentCount
				set theAttachment to item theAttachmentIndex of theAttachments
				set theAttachmentFileName to name of theAttachment
				set theFullAttachmentPath to "Macintosh HD:tmp:" & theAttachmentFileName
				
				save theAttachment in theFullAttachmentPath
				
				try
					tell front document of application "OmniFocus"
						tell the note of theTask
							make new file attachment with properties {file name:theFullAttachmentPath, embedded:true}
						end tell
					end tell
				on error errmesg number errn
					write_error_log(errmesg & return & return & "error number: " & (errn as text))
				end try
				tell application "Finder"
					if exists file theFullAttachmentPath then
						delete file theFullAttachmentPath
					end if
				end tell
			end repeat
		end if
		
	end process_message
	
	on perform mail action with messages theMessages
		try
			set theMessageCount to count of theMessages
			repeat with theMessageIndex from 1 to theMessageCount
				my process_message(item theMessageIndex of theMessages)
			end repeat
		on error m number n
			tell application "OmniFocus"
				log "Exception in Mail action: (" & n & ") " & m
			end tell
		end try
	end perform mail action with messages
	
end using terms from
 
I am desperately trying to get this to work. I don't know AppleScript, so any help would be appreciated.

I don't need to worry about multiple actions. I just want to be able to send an email from my work PC to my MBP and have OF include any attachments in the task.

I tried replacing 'Macintosh HD' with the name of my disk, but this didn't do the trick.

FWIW, I was successful in switching the 'Fwd: ' to 'FW: ' and changing the 6 to 5, so I know I'm saving the script correctly and pointing Mail to it properly.

Can anyone help me get this to work so I can get attachments in my task through the mail rule?

Many thanks in advance,
Ben
 
Here's the script as I currently have it:

Code:
-- Copyright 2007 The Omni Group.  All rights reserved.
--
-- $Header: svn+ssh://source.omnigroup.com/Source/svn/Omni/branches/OmniFocus/1.x/OmniGroup/Applications/Focus/App/Preferences/MailAction.applescript 107989 2009-01-23 22:26:17Z xmas $

using terms from application "Mail"
	-- Trims "foo <foo@bar.com>" down to "foo@bar.com"
	on trim_address(theAddress)
		try
			set AppleScript's text item delimiters to "<"
			set WithoutPrefix to item 2 of theAddress's text items
			set AppleScript's text item delimiters to ">"
			set MyResult to item 1 of WithoutPrefix's text items
		on error
			set MyResult to theAddress
		end try
		set AppleScript's text item delimiters to {""} --> restore delimiters to default value
		return MyResult
	end trim_address
	
	
	on process_message(theMessage)
		tell application "OmniFocus"
			log "OmniFocus calling process_message in MailAction script"
		end tell
		-- Allow the user to type in the full sender address in case our trimming logic doesn't handle the address they are using.
		set theSender to sender of theMessage
		set trimmedSender to my trim_address(theSender)
		tell application "OmniFocus"
			set AllowedSender to allowed mail senders
			if AllowedSender does not contain trimmedSender and AllowedSender does not contain theSender then
				return
			end if
		end tell
		
		set theAttachments to mail attachments of the theMessage
		set theAttachmentCount to count of theAttachments
		
		set theSubject to subject of theMessage
		set singleTask to false
		if (theSubject starts with "FW: ") then
			-- Whole forwarded messages shouldn't split.
			set singleTask to true
			set theSubject to text 5 through -1 of theSubject
		end if
		set theText to theSubject & return & content of theMessage
		tell application "OmniFocus"
			tell default document
				parse tasks with transport text theText as single task singleTask
			end tell
		end tell
		
		set theTaskCount to the count of theTasks
		if theTaskCount > 0 and theAttachmentCount > 0 then
			set theTask to the first item in theTasks
			
			repeat with theAttachmentIndex from 1 to theAttachmentCount
				set theAttachment to item theAttachmentIndex of theAttachments
				set theAttachmentFileName to name of theAttachment
				set theFullAttachmentPath to "Kajind:tmp:" & theAttachmentFileName
				
				save theAttachment in theFullAttachmentPath
				
				try
					tell front document of application "OmniFocus"
						tell the note of theTask
							make new file attachment with properties {file name:theFullAttachmentPath, embedded:true}
						end tell
					end tell
				on error errmesg number errn
					write_error_log(errmesg & return & return & "error number: " & (errn as text))
				end try
				tell application "Finder"
					if exists file theFullAttachmentPath then
						delete file theFullAttachmentPath
					end if
				end tell
			end repeat
		end if
		
	end process_message
	
	try
		-- put up a growl notification
		tell application "GrowlHelperApp"
			set the allNotificationsList to {"Mail Notification"}
			set the enabledNotificationsList to {"Mail Notification"}
			register as application "OmniFocus" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "OmniFocus"
			notify with name "Mail Notification" title "OmniFocus recieved Mail task" description theSubject application name "OmniFocus"
		end tell
	end try
	
	on perform mail action with messages theMessages
		try
			set theMessageCount to count of theMessages
			repeat with theMessageIndex from 1 to theMessageCount
				my process_message(item theMessageIndex of theMessages)
			end repeat
		on error m number n
			tell application "OmniFocus"
				log "Exception in Mail action: (" & n & ") " & m
			end tell
		end try
	end perform mail action with messages
end using terms from
 
This would be no different from how the clip-o-tron in Mail works, right? Is that a script? I wonder if there is code there to use for this?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail clipping: no attachments in Lion [A: caused by change to Mail.app in 10.7] lgallerano OmniFocus 1 for Mac 36 2014-02-20 04:04 PM
How to process mail with attachments with mail rules. bjgreenberg OmniFocus 1 for Mac 2 2011-08-26 01:39 PM
Missing Omnifocus Mail Integration in Mail Version 4.3 (1081) cummins OmniFocus 1 for Mac 1 2010-07-12 04:01 AM
Mail integration Mixalis OmniFocus 1 for Mac 2 2008-07-15 05:33 AM
Mail Integration -vs- Mail Signatures choppingblock OmniFocus 1 for Mac 11 2008-06-15 10:55 AM


All times are GMT -8. The time now is 02:16 AM.


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