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

 
Send email to OmniOutliner Script Thread Tools Search this Thread Display Modes
Everyone:

These forums have been so great to me that I felt I needed to give something back. I have stolen a number of scripts from this board and changed them for my own use. The attached script was inspired by jharrison's create project folder and outline script but has elements stolen from all over the place including here and the growl forums.

What I wanted to achieve is the ability to select a group of emails and have them entered into an Omni Outliner document in a special row called "Emails" This script first shows a chooser box that list all of the projects in a directory. These represent my project folders. Once a project is selected it checks for the existence of a OmniOutliner document with the project name and notes as the file name. It then checks to see if there is a row called Emails and creates it if necessary. It then copies information from each email and creates a child row for that email. It also creates a link back to the original email. It does not add the attachments as I don't know how to implement that. It also sends a Growl message for each message added to the notes outline using whatever icon is assigned to the projects folder.

I have no idea if this would be useful for anyone other than me and I am probably the worst AppleScript creator EVER so don't look to me to fix issues with the script :) User BEWARE!!! :eek: And NO LOL!!!! :rolleyes:

Enjoy!!!

I am also posting this to the OmniFocus section as that is where my inspiration started

Code:
--General Settings
property projectsDir : (path to documents folder as text) & "VM Shared Folders:VM My Documents:Projects"
property ooPrefix : "• "
property ooSuffix : " notes"
property ooExtension : ".oo3"
property emailHeaderTerms : {"From", "Date", "To", "Cc", "Bcc", "Subject"}

--Growl Notification Settings:
property growlAppName : "My Scripts"
property scriptStartNotification : "Script Began"
property scriptFinishNotification : "Script Completed"
property defaultNotifications : {scriptFinishNotification}
property allNotifications : defaultNotifications & {scriptStartNotification}
property iconLoaningApplication : "Mail.app"
property alertIcon : "~/Documents/VM Shared Folders/VM My Documents/Projects/"

tell application "System Events"
	set growlisRunning to (count of (every process whose name is "GrowlHelperApp")) > 0
end tell

tell application "Finder"
	-- Get Project Name
	set projectList to get name of folders of folder projectsDir
	set projectName to choose from list projectList with prompt "Choose Project:"
	if projectName is false then return
	
	-- Set Project Directory and Project File Name
	set projEmailsDir to projectsDir & ":" & projectName
	set projEmailsName to ooPrefix & projectName & ooSuffix & ooExtension
	
	-- Check for Existence of Email Outline and Create if necessary
	if not (file (projEmailsDir & ":" & projEmailsName) exists) then
		set outlineDoc to duplicate projectsDir & ":Project Template.oo3" to alias projEmailsDir
		set name of outlineDoc to projEmailsName
	end if
end tell

tell application "OmniOutliner Professional"
	set outlineDoc to open (projEmailsDir & ":" & projEmailsName)
	try
		set rowptr to first row of outlineDoc whose topic is "Emails"
	on error
		set rowptr to make new row with properties {topic:"Emails"} at end of outlineDoc
	end try
	set expanded of rowptr to true
end tell

tell application "Mail"
	set theMessages to selection
	repeat with theMessage in theMessages
		set message_id to "message://%3c" & message id of theMessage & "%3e"
		set message_sender to (extract name from sender of theMessage)
		set message_header_raw to all headers of theMessage
		set message_header to ""
		repeat with textLine in paragraphs of message_header_raw
			if length of textLine is greater than 0 then
				if emailHeaderTerms contains word 1 of textLine then
					set message_header to message_header & textLine & return
				end if
			end if
		end repeat
		set message_subject to (subject of theMessage)
		set theContent to (content of theMessage)
		set receivedDate to (date received of theMessage) as string
		set rowTopic to receivedDate & "-" & message_subject
		set rowNotes to "Link to Original Message: " & message_id & return & return & message_header & return & theContent
		tell application "OmniOutliner Professional" to tell outlineDoc
			set newRow to make new row with properties {topic:rowTopic, note:rowNotes, selected:true} at end of children of rowptr
		end tell
		set theNotification to "Subject: " & message_subject & return & "From: " & message_sender & return & "Date: " & receivedDate & return & "Project: " & projectName as Unicode text
		if growlisRunning then my notify("Send to Project Notes", theNotification, scriptFinishNotification)
	end repeat
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 icon of file alertIcon
	end tell
end notify
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Task VIA Email mctheriot OmniFocus 1 for Mac 5 2012-03-10 11:55 PM
Mail script: Send to OF unreliable Mixalis OmniFocus Extras 10 2010-06-01 06:34 PM
Email to OmniOutliner Script cjlemonier OmniFocus Extras 0 2009-09-15 09:49 AM
OmniOutliner "Send to OmniFocus" Script curt.clifton OmniFocus 1 for Mac 4 2007-06-20 06:04 PM


All times are GMT -8. The time now is 12:04 AM.


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