Exporting Omnifocus project list for use in MailTags
In the thread '[URL="http://forums.omnigroup.com/showthread.php?t=18580"]Applescript for finding an OmniFocus project quickly[/URL]' 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 [I][INDENT]~/Library/Application Support/MailTags[/INDENT][/I] or [I][INDENT]~/Library/Mail[/INDENT][/I] (My system - OS X 10.6.5 Mailtags 2.5 Mail 4.4 - does not have folders with the path [I][INDENT]/Library/Application Support/Mail[/INDENT][/I] or [I][INDENT]~/Library/Application Support/Mail[/INDENT][/I] ) |
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 [I]mailTagsProjects[/I] array in
[INDENT]~/Library/Preferences/ca.indev.MailTags.plist[/INDENT] and also changes in the Projects table of the database at [INDENT]~/Library/Mail/MailTagsData.db[/INDENT] I personally might hesitate to mess with this at a low level through scripts ... [COLOR="White"]--[/COLOR] |
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[INDENT][I]~/Library/Preferences/ca.indev.MailTags.plist[/I][/INDENT]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 [/CODE] |
MailTags 2.6 will now read projects from Omnifocus
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. |
All times are GMT -8. The time now is 01:04 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.