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 > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

OmniFocus create task from email Thread Tools Search this Thread Display Modes
I'm trying to modify the default mail integration script to include attachments. I've never worked with AppleScript, and I'm really not sure what I'm doing, but this is what I have so far... Any help at all would be appreciated.

using terms from application "Mail"
	-- Trims "foo " down to ""
	on trim_address(theAddress)
			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
			end if
		end tell
		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 tTasks to parse tasks with transport text theText as single task singleTask
				set theTask to item 1 of tTasks
				tell application "Mail"
					set attachCount to count of mail attachments of theMessage
					repeat with theAttachmentIndex from 1 to attachCount
						set theAttachment to item theAttachmentIndex of mail attachments of theMessage
						tell application "OmniFocus"
							set theNote to note of theTask
							add item theAttachment to attachments of theNote
							set note of theTask to theNote
						end tell
					end repeat
				end tell
			end tell
		end tell
	end process_message
	on perform mail action with messages theMessages
			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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically create a waiting for task? alexius OmniFocus 1 for Mac 29 2013-07-11 04:27 AM
Create Task with Label kennedyma OmniFocus 1 for Mac 1 2011-06-01 08:05 AM
AppleScript help: Create sub-task, project from task iNik OmniFocus Extras 3 2007-12-05 08:53 AM
Script to create an email from a task in OF. Tinchohs OmniFocus Extras 3 2007-10-31 12:53 PM
Send Task / Receive Task update by Email samaparicio OmniFocus 1 for Mac 0 2007-07-10 07:58 PM

All times are GMT -8. The time now is 05:35 PM.

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