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

 
Exporting Omnifocus project list for use in MailTags Thread Tools Search this Thread Display Modes
In the thread 'Applescript for finding an OmniFocus project quickly' RobTrew and I started to discuss an AppleScript based in the SQL query part of the 'quick project find'-script from Rob to export all projects that are neither completed nor dropped from Omnifocus for important into MailTags.

This would be a 'oneway-sync' and not the final and perfect solution, but at least a workable one. We still want Indev to ship MailTags 3.0 with full Omnifocus integration ;-)

The discussion was left at the point where we discussed to put the export directly into Apple's .plist format and overwrite the last .plist, which has some pros (saving a manual step to important a flat text file into MailTags), but also some risk, since any projects not in Omnifocus, but created in MailsTags since the last import will be overwritten.

The text file approach is supported by MailTags out of the box and allows for appending projects rather than replacing. There are some "pros" I can see with this approach, but also some "cons". For example you would need to find a way to determine the delta in Omnifocus from the last export if you want to consistently append projects to the list.

Of course the text import also supports replacement of the project list, but why then not saving that manual steps and directly replace the .plist?

By the way, Rob, the .plist I am referring should be located in '/Library/Application Support/Mail'.

So how would people like to be able to import a Omnifocus Project List into MailTags?
 
Filename ?

No obvious sign of a matching plist in

~/Library/Application Support/MailTags

or
~/Library/Mail

(My system - OS X 10.6.5 Mailtags 2.5 Mail 4.4 - does not have folders with the path
/Library/Application Support/Mail

or
~/Library/Application Support/Mail

)

Last edited by RobTrew; 2010-12-30 at 11:23 PM..
 
Indeed, I can't find that plist file back either, although I was sure it existed.

I have emailed Scott from Indev to provide guidance. Let's see what he comes back with.

Cheers,

-Sven
 
Wow! I just started working on this exact same thing. I posted the same question over on the forums on indev.ca. Hopefully Scott has a good way to get to those preferences.
 
Adding a project and getting the shell to look for recently modified files suggests the mailTagsProjects array in
~/Library/Preferences/ca.indev.MailTags.plist
and also changes in the Projects table of the database at
~/Library/Mail/MailTagsData.db
I personally might hesitate to mess with this at a low level through scripts ...

--

Last edited by RobTrew; 2010-12-30 at 11:50 AM..
 
But here is a rough sketch of what it might look like. Note that Mail must be closed. (The project list in the plist file is only read when Mail is launched).

(OmniFocus doesn't have to be running).

Very experimental code, so back up
~/Library/Preferences/ca.indev.MailTags.plist
and proceed with caution. No guarantees that it wont eat your existing MailTags project list. This draft aims to import the OF projects with the prefix "OF:" to distinguish them from other projects in the Mailtags project list, which will be left intact.

In this draft, if a project is completed in OF, it will be removed from the MailTags prompt list (though not from any tagged emails) when the script is next run.

Code:
property pTitle : "Merge OF Project list into Mailtags Project list"
property pVer : "0.04"

property pstrOFPrefix : "OF:"
-- MUST START WITH THE KEYWORD 'WHERE'  (unless completely blank: "" )
property pstrProjectSet : "where dateCompleted is null"

-- Some snippets illustrating a possible approach to merging the OmniFocus project list with the MailTags project list
-- Intended for reference only

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

property pstrPListPath : "~/Library/Preferences/ca.indev.MailTags.plist"
property pstrDBPath : "~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2"

property pstrProjectSQL : "select \"" & pstrOFPrefix & "\" || name, \"<eor>\" from projectinfo p join task on p.pk=task.persistentidentifier " & pstrProjectSet & " order by name"

property plstMTProjects : {}
property plstOFProjects : {}
property plstUnion : {}
property pEOR : "<eor>"
property pFldDelim : "<fldelim>"

on run
	-- WARN USER IF MAIL IS RUNNING
	tell application id "com.apple.systemevents"
		set blnWarned to false
		set blnWasRunning to false
		repeat while (count of (processes where title = "Mail")) > 0
			if not blnWarned then
				set blnWasRunning to true
				activate
				set varResponse to display dialog "This script requires Mail to be closed ..." buttons {"Esc", "Close Mail"} with title pTitle & "  " & pVer
				if button returned of varResponse = "Esc" then return
				set blnWarned to true
				tell application id "com.apple.mail" to quit
			end if
			do shell script "sleep " & (0.5) as string
		end repeat
		
		-- READ THE EXISTING MAILTAGS PROPERTY LIST
		tell contents of property list file pstrPListPath
			set refPlist to a reference to (property list item "mailTagsProjects")
			set lstRecs to value of refPlist
			if length of lstRecs > 0 then
				set {plstMTProjects, propsOther} to {items 1 thru -2 of lstRecs, item -1 of lstRecs}
			else
				set {plstMTProjects, propsOther} to {{}, {}}
			end if
			repeat with i from 1 to length of plstMTProjects
				set item i of plstMTProjects to |title| of item i of plstMTProjects
			end repeat
			
			-- READ THE FULL OMNIFOCUS PROPERTY LIST (OmniFocus does not need to be running)
			my RunSQL(pstrProjectSQL, "All projects")
			set lngProjects to length of plstOFProjects
			
			-- COMBINE THE TWO LISTS OF NAMES (MAILTAGS & OMNIFOCUS)
			-- 			set plstUnion to my union(plstMTProjects, plstOFProjects)
			set plstUnion to my MergeLists(plstOFProjects, plstMTProjects)
			
			-- AND TURN THEM INTO RECORDS WITH |TITLE| FIELDS
			repeat with i from 1 to length of plstUnion
				set item i of plstUnion to {|title|:item i of plstUnion}
			end repeat
			if length of propsOther > 0 then set end of plstUnion to propsOther
			
			-- THEN PUT THEM BACK INTO THE PLIST FILE
			set value of refPlist to plstUnion
		end tell
		
		activate
		if blnWasRunning then
			set varResponse to display dialog (lngProjects as string) & " OmniFocus Projects now in MailTags project list." buttons {"Esc", "Re-launch Mail"} with title pTitle & "  " & pVer
			if button returned of varResponse = "Esc" then return
			tell application id "com.apple.mail" to activate
		else
			display dialog (lngProjects as string) & " OF Projects now in MailTags project list." buttons {"OK"} with title pTitle & "  " & pVer
		end if
	end tell
end run

on RunSQL(strSQL, strUserQuery)
	set strCmd to "sqlite3 -separator '" & pFldDelim & "' " & pstrDBPath & space & quoted form of strSQL
	set text item delimiters to pFldDelim & pEOR & return -- strip out the end of line \r as well as the record delimiter
	try
		set plstOFProjects to text items 1 thru -2 of ((do shell script strCmd) & return)
		set pblnError to false
	on error strError
		set plstOFProjects to {strUserQuery & return & return & strError}
		set pblnError to true
	end try
end RunSQL

-- Specified OF projects preceded by  any members of MailTags projects that do NOT begin with the OF prefix
on MergeLists(lstOF, lstMT)
	repeat with i from 1 to length of lstMT
		set strProj to item i of lstMT
		if not (strProj begins with pstrOFPrefix) then set beginning of lstOF to strProj
	end repeat
	lstOF
end MergeLists

Last edited by RobTrew; 2011-01-01 at 05:13 AM.. Reason: ver 0.04
 
Just a quick post to let you know that I released MailTags 2.6 last week. One of the improvements is "external projects" When displaying projects in the MailTags menus, MailTags will now pull the current projects from OmniFocus and display them in a separate section in the project menu.

So you no longer will have to try to keep your MailTags projects in sync with OF -- it will do it automatically.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store project to do list/ advise from people in omnifocus ? pakiyabhai OmniFocus 1 for Mac 0 2011-05-23 11:59 PM
Using MailTags with OmniFocus egorges OmniFocus Extras 3 2010-01-25 04:43 PM
Omnifocus list of project list Jupiter OmniFocus Extras 0 2009-11-15 05:18 AM
Using MailTags With OmniFocus Brian OmniFocus 1 for Mac 19 2009-08-05 08:35 AM
Exporting as UL List? lolajl OmniOutliner 3 for Mac 2 2009-06-01 05:31 PM


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


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