├── Prepare task completion report.scpt └── README.md /Prepare task completion report.scpt: -------------------------------------------------------------------------------- 1 | -- This script is based on the code here: http://www.tuaw.com/2013/02/18/applescripting-omnifocus-send-completed-task-report-to-evernot/ 2 | 3 | -- Prepare a name for the new Evernote note 4 | set theNoteName to "OmniFocus Completed Task Report" 5 | set theNotebookName to ".Inbox" 6 | 7 | -- Prompt the user to choose a scope for the report 8 | activate 9 | set theReportScope to choose from list {"Today", "Yesterday", "This Week", "Last Week", "This Month", "Last Month"} default items {"Yesterday"} with prompt "Generate a report for:" with title theNoteName 10 | if theReportScope = false then return 11 | set theReportScope to item 1 of theReportScope 12 | 13 | -- Calculate the task start and end dates, based on the specified scope 14 | set theStartDate to current date 15 | set hours of theStartDate to 0 16 | set minutes of theStartDate to 0 17 | set seconds of theStartDate to 0 18 | set theEndDate to theStartDate + (23 * hours) + (59 * minutes) + 59 19 | 20 | if theReportScope = "Today" then 21 | set theDateRange to date string of theStartDate 22 | else if theReportScope = "Yesterday" then 23 | set theStartDate to theStartDate - 1 * days 24 | set theEndDate to theEndDate - 1 * days 25 | set theDateRange to date string of theStartDate 26 | else if theReportScope = "This Week" then 27 | repeat until (weekday of theStartDate) = Sunday 28 | set theStartDate to theStartDate - 1 * days 29 | end repeat 30 | repeat until (weekday of theEndDate) = Saturday 31 | set theEndDate to theEndDate + 1 * days 32 | end repeat 33 | set theDateRange to (date string of theStartDate) & " through " & (date string of theEndDate) 34 | else if theReportScope = "Last Week" then 35 | set theStartDate to theStartDate - 7 * days 36 | set theEndDate to theEndDate - 7 * days 37 | repeat until (weekday of theStartDate) = Sunday 38 | set theStartDate to theStartDate - 1 * days 39 | end repeat 40 | repeat until (weekday of theEndDate) = Saturday 41 | set theEndDate to theEndDate + 1 * days 42 | end repeat 43 | set theDateRange to (date string of theStartDate) & " through " & (date string of theEndDate) 44 | else if theReportScope = "This Month" then 45 | repeat until (day of theStartDate) = 1 46 | set theStartDate to theStartDate - 1 * days 47 | end repeat 48 | repeat until (month of theEndDate) is not equal to (month of theStartDate) 49 | set theEndDate to theEndDate + 1 * days 50 | end repeat 51 | set theEndDate to theEndDate - 1 * days 52 | set theDateRange to (date string of theStartDate) & " through " & (date string of theEndDate) 53 | else if theReportScope = "Last Month" then 54 | if (month of theStartDate) = January then 55 | set (year of theStartDate) to (year of theStartDate) - 1 56 | set (month of theStartDate) to December 57 | else 58 | set (month of theStartDate) to (month of theStartDate) - 1 59 | end if 60 | set month of theEndDate to month of theStartDate 61 | set year of theEndDate to year of theStartDate 62 | repeat until (day of theStartDate) = 1 63 | set theStartDate to theStartDate - 1 * days 64 | end repeat 65 | repeat until (month of theEndDate) is not equal to (month of theStartDate) 66 | set theEndDate to theEndDate + 1 * days 67 | end repeat 68 | set theEndDate to theEndDate - 1 * days 69 | set theDateRange to (date string of theStartDate) & " through " & (date string of theEndDate) 70 | end if 71 | 72 | -- Begin preparing the task list as HTML 73 | set theProgressDetail to "

Completed Tasks


" & theDateRange & "


" 74 | set theInboxProgressDetail to "
" 75 | 76 | -- Retrieve a list of projects modified within the specified scope 77 | set modifiedTasksDetected to false 78 | tell application "OmniFocus" 79 | tell front document 80 | set theModifiedProjects to every flattened project where its modification date is greater than theStartDate 81 | -- Loop through any detected projects 82 | repeat with a from 1 to length of theModifiedProjects 83 | set theCurrentProject to item a of theModifiedProjects 84 | -- Retrieve any project tasks modified within the specified scope 85 | set theCompletedTasks to (every flattened task of theCurrentProject where its completed = true and completion date is greater than theStartDate and completion date is less than theEndDate and number of tasks = 0) 86 | -- Loop through any detected tasks 87 | if theCompletedTasks is not equal to {} then 88 | set modifiedTasksDetected to true 89 | -- Append the project name to the task list 90 | set theProgressDetail to theProgressDetail & "

" & name of theCurrentProject & "

" & return & "
" & return 97 | end if 98 | end repeat 99 | -- Include the OmniFocus inbox 100 | set theInboxCompletedTasks to (every inbox task where its completed = true and completion date is greater than theStartDate and completion date is less than theEndDate and number of tasks = 0) 101 | -- Loop through any detected tasks 102 | if theInboxCompletedTasks is not equal to {} then 103 | set modifiedTasksDetected to true 104 | -- Append the project name to the task list 105 | set theInboxProgressDetail to theInboxProgressDetail & "

" & "Inbox" & "

" & return & "
" & return 112 | end if 113 | 114 | end tell 115 | end tell 116 | set theProgressDetail to theProgressDetail & theInboxProgressDetail & "" 117 | 118 | -- Notify the user if no projects or tasks were found 119 | if modifiedTasksDetected = false then 120 | display alert "OmniFocus Completed Task Report" message "No modified tasks were found for " & theReportScope & "." 121 | return 122 | end if 123 | 124 | -- Create the note in Evernote. 125 | tell application "Evernote" 126 | activate 127 | set theReportDate to do shell script "date +%Y-%m-%d" 128 | set theNote to create note notebook theNotebookName title theReportDate & " :: " & theNoteName with html theProgressDetail 129 | open note window with theNote 130 | end tell 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a directory of Apple Scripts to augment the functionality of OmniFocus on the Mac 2 | 3 | THIS CODE CARRIES NO WARRANTY. Always backup your data before running scripts that interact with your data. 4 | 5 | To get the source code to appear on GitHub, I used the [technique explained by Daniel Trebbien on StackOverflow](http://stackoverflow.com/questions/7641806/how-would-you-put-an-applescript-script-under-version-control). 6 | 7 | ## Completed Task Report ## 8 | Filename: "Prepare task completion report.scpt" 9 | 10 | Use this script to create a summary list of completed OmniFocus tasks in Evernote based on your selected timeframe. 11 | 12 | This script is based on the code [here](http://www.tuaw.com/2013/02/18/applescripting-omnifocus-send-completed-task-report-to-evernot/). 13 | 14 | I made some minor modifications and added the code from the first comment that adds the completed tasks in the inbox. 15 | 16 | ### Instructions ### 17 | 18 | 1. Add this script to ~/Library/Scripts/Applications/OmniFocus/ 19 | 2. Add the Script menu to your menu bar 20 | 3. Bring OmniFocus to the front 21 | 4. click on the Script icon in the menubar and select the script, then select the duration in the pop-up 22 | 5. If successful, you will find a new note in your Evernote inbox 23 | --------------------------------------------------------------------------------