Apple Script to backup each context separately
Hello,
I need a simple apple script which open the software“OmniFocus” and export each “subcontext” as a csv file. Right now I have to click on each subcontext, click onfile-> export which takes a lot of time. I want to automate the processusing apple script. I already have a script which open Omnifocus, and export everything. Best Regards |
Here is a rough draft with which you are welcome to experiment
[CODE]-- Export tasks of each Omnifocus context to a separate .csv text file on the User Desktop -- Ver 0.01 -- Copyright ©2010 Robin Trew, UK. All rights reserved. property pOutPutFolder : path to desktop -- property pFolderName : "OFContexts " property pstrHeader : "Task ID,Type,Task,Project,Context,Start Date,Due Date,Completion Date,Duration,Flagged,Notes" & return property pDblQuote : "\"" property pDbldblQuote : "\"\"" property pComma : "," property pType : ",Action" on run set lstContextTree to ContextTasks() WriteContextFiles(lstContextTree) end run on WriteContextFiles(lstContextTree) if length of lstContextTree > 0 then repeat with oContext in lstContextTree set {strContextName, lstContextChiln, lstTasks} to oContext if length of lstTasks > 0 then set lngTask to 1 set strCSV to pstrHeader repeat with oTask in lstTasks set {strTaskName, lstTaskChiln, strProject, strContext, dteStart, dteDue, dteDone, lngMins, blnFlagged, strNote} to oTask set strCSV to strCSV & (lngTask as string) & pType & WrapQuote(strTaskName) & WrapQuote(strProject) & WrapQuote(strContext) if dteStart is not missing value then set strCSV to strCSV & WrapQuote(dteStart as string) else set strCSV to strCSV & pComma end if if dteDue is not missing value then set strCSV to strCSV & WrapQuote(dteDue as string) else set strCSV to strCSV & pComma end if if dteDone is not missing value then set strCSV to strCSV & WrapQuote(dteDone as string) else set strCSV to strCSV & pComma end if if lngMins is not missing value then set strCSV to strCSV & pComma & (lngMins as string) else set strCSV to strCSV & pComma end if set strCSV to strCSV & pComma if blnFlagged then set strCSV to strCSV & "1" else set strCSV to strCSV & "0" end if if length of strNote > 0 then set strCSV to strCSV & WrapQuote(strNote) & return else set strCSV to strCSV & pComma & return end if set lngTask to lngTask + 1 end repeat WriteCSVFile(strCSV, strContextName) end if if length of lstContextChiln > 0 then WriteContextFiles(lstContextChiln) end repeat end if end WriteContextFiles on WriteCSVFile(strText, strFileName) set fTemp to (pOutPutFolder & strFileName & ".CSV") as text try close access file fTemp end try try open for access file fTemp with write permission on error display dialog strFileName & ".csv seems to be open in another program ... Close and try again." return end try set eof file fTemp to 0 write strText to file fTemp starting at eof close access file fTemp end WriteCSVFile -- wrap string in double quotes if it contains any commas or double quotes -- and duplicate any embedded double quotes -- ALSO precede with a comma ... on WrapQuote(strField) set blnWrap to strField contains "\"" if blnWrap then set strOldDelim to text item delimiters set text item delimiters to pDblQuote set lstWords to text items of strField set text item delimiters to pDbldblQuote set strNew to lstWords as string set text item delimiters to strOldDelim pComma & pDblQuote & strNew & pDblQuote else if strField contains pComma then pComma & pDblQuote & strField & pDblQuote else pComma & strField end if end if end WrapQuote -- Return a nested applescript list representing the context tree, with attached tasks on ContextTasks() tell application "OmniFocus" tell default document set lstContexts to contexts if length of lstContexts > 0 then my ContextTree(lstContexts) else {} end if end tell end tell end ContextTasks -- Translate a collection of contexts to a nested applescript list on ContextTree(lstContexts) using terms from application "OmniFocus" set lstTree to {} repeat with oContext in lstContexts tell oContext set lstChiln to contexts if length of lstChiln > 0 then set lstChiln to my ContextTree(lstChiln) set lstTasks to tasks if length of lstTasks > 0 then set lstTasks to my TaskTree(lstTasks) set end of lstTree to {name, lstChiln, lstTasks} end tell end repeat lstTree end using terms from end ContextTree -- Translate a collection of tasks to a nested applescript list on TaskTree(lstTasks) using terms from application "OmniFocus" set lstTree to {} repeat with oTask in lstTasks tell oTask set lstChiln to tasks if length of lstChiln > 0 then set lstChiln to my TaskTree(lstChiln) set oContext to context of oTask if oContext is missing value then set strContext to "" else set strContext to name of oContext end if set oProject to containing project of oTask if oProject is missing value then set strProject to "" else set strProject to name of oProject end if set end of lstTree to {name, lstChiln, strProject, strContext, start date, due date, completion date, estimated minutes, flagged, note} end tell end repeat lstTree end using terms from end TaskTree[/CODE] |
Thanks!
I will try! |
All times are GMT -8. The time now is 02:16 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.