Guest
2010-06-23, 11:09 PM
Quote:
Originally Posted by vinyl_warrior
Does anyone happen to have a script that will toggle a project from parallel to sequential or vice versa? It would be ideal if all I had to do is have a task currently selected and have the script change the project.
|
As parent tasks within the same project can have different parallel/sequential settings, I am guessing that you want to
- Toggle the project's status
- Reset the status of all the contained parent tasks to match that of the project
If so, then then you should edit the value of the property
pblnTasksChangeWithProject near the top of the script to
true
If, however, you just want to toggle the status of the project, and leave unchanged the state of any parent tasks within the project, then you should leave the value of the property
pblnTasksChangeWithProject as
false
Code:
-- Toggles the selected project(s)
-- (or the project(s) of the selected task(s))
-- between sequential and parallel
-- If this property is set to TRUE,
-- the status of ALL PARENT TASKS is changed to match the
-- new status of the project itself.
-- if it is set to false, ONLY THE PROJECT ITSELF is toggled,
-- and the status of any contained parent tasks is left unchanged.
property pblnTasksChangeWithProject : true
tell application "OmniFocus"
tell front document window of default document
set refSeln to a reference to (selected trees of content)
if (count of refSeln) < 1 then ¬
set refSeln to a reference to (selected trees of sidebar)
if (count of refSeln) < 1 then return
-- gather a list of selected projects to be toggled
set lstObjects to value of refSeln
set lstProjects to {}
repeat with oObj in lstObjects
set cClass to class of oObj
if cClass is project then
if not my IsMember(oObj, lstProjects) then ¬
set end of lstProjects to oObj
else if cClass is task then
set oProj to containing project of oObj
if not my IsMember(oProj, lstProjects) then ¬
set end of lstProjects to oProj
end if
end repeat
-- toggle each project
repeat with oProj in lstProjects
set blnNewState to not sequential of oProj
my SetState(oProj, blnNewState)
end repeat
end tell
end tell
-- Either toggles just the project itself
-- or, if pblnTasksChangeWithProject is TRUE,
---- (see top of script)
---- recursively sets all tasks to match the
---- new status of the project
on SetState(oObject, blnNewState)
using terms from application "OmniFocus"
tell oObject
set sequential to blnNewState
if pblnTasksChangeWithProject then
set lstTasks to tasks
repeat with oTask in lstTasks
my SetState(oTask, blnNewState)
end repeat
end if
end tell
end using terms from
end SetState
-- Simple test for list membership
-- used to ensure that we don't toggle the same project twice
on IsMember(oElement, lstList)
using terms from application "OmniFocus"
repeat with oItem in lstList
if id of oItem is id of oElement then return true
end repeat
false
end using terms from
end IsMember
Last edited by RobTrew; 2010-06-24 at 12:40 AM..