(* This script clean up all completed actions from a certain scope of defined projects or projects inside a folder. Those actions are redundant auto repeated tasks get generated and discarded daily. by Zhenkai Jiang *) on cleanupRoutineProject(projectName) using terms from application "OmniFocus" set interestingTasks to (every flattened task of projectName where its completed = true) repeat with a from 1 to length of interestingTasks set theCurrentTask to item a of interestingTasks tell theCurrentTask delete end tell end repeat end using terms from end cleanupRoutineProject on main() set dateToday to date (short date string of (current date)) tell application "OmniFocus" tell default document set routetineFolder to first flattened folder whose name is "Personal Routines" set routineProjects to (name of every flattened project of routetineFolder) set flattenRoutineProjects to {"Keep Organising myself - Routine", "Work Routine", "Memory Refresh (Routine)", "Financial Routines"} set allRoutineProjects to routineProjects & flattenRoutineProjects -- clean up all flatten route projects repeat with routeProject in allRoutineProjects set interestingProject to (first flattened project whose name is routeProject) --display dialog routeProject buttons {"OK"} default button "OK" with title pTitle my cleanupRoutineProject(interestingProject) end repeat end tell -- display dialog cc buttons {"OK"} default button "OK" with title pTitle end tell end main main()