The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   Mass de-flag in context/perspective script. (

roadtrip 2011-12-26 10:07 PM

Mass de-flag in context/perspective script.
Ho-ho-hello. Getting ready for 012. My desperate daily workflow requires a script that will un-flag ALL items in a given Context/Perspective. Willing to fund a PayPal account. pls help. thx.

RobTrew 2011-12-27 12:50 AM

I think you should be able to deflag everything that is shown in a particular perspective with something like this.

[CODE]tell application id "OFOC"
tell front document window of front document
set refTrees to a reference to trees of content

repeat with oProj in (value of refTrees where class of its value is project) as list
set flagged of oProj to false
end repeat

repeat with oValue in (value of refTrees where class of its value is task) as list
my ClearFlag(oValue)
end repeat

-- if we are grouping by flag, the Flagged tree may vanish at run time
repeat with i from (count of refTrees) to 1 by -1
set oTree to item i of refTrees
repeat with oTask in (value of descendant trees of oTree) as list
my ClearFlag(oTask)
end repeat
end repeat

-- Note a bug in the GUI: project flags will not appear as cleared until the window is closed & reopened
-- the following simply the view mode back and forth to force a repaint
-- a time-waster, but works around the GUI bug
set lstView to available view mode identifiers
if item 1 of lstView = selected view mode identifier then set lstView to reverse of lstView
repeat with oView in lstView
set selected view mode identifier to oView
end repeat
end tell
end tell

on ClearFlag(oTask)
tell application id "OFOC"
set flagged of oTask to false
set oParent to container of oTask
repeat while class of oParent is in {task, project}
set flagged of oParent to false
set oParent to container of oParent
end repeat
end tell
end ClearFlag


Note that OmniFocus still seems to have a screen refresh bug - when the flagging of a Project is cleared by script, the flag icon is not immediately repainted/cleared - you have to close and reopen the window to see what has really happened.
Flags on cleared tasks, however, should immediately vanish.

I remember this bug from years ago, so I am a bit surprised to notice that it is still there. Certainly worth a bug report through OF > [B]Help > Send Feedback ...[/B]


roadtrip 2012-01-17 03:26 PM

Thank you!!!

roadtrip 2012-01-23 01:25 PM

Hi there! Thank you again for providing this script.

Since I use the script almost exclusively in context mode, I thought I would offer a little feedback on its usage.

- The script indeed successfully de-flags tasks in my context/perspective. I immediately see the flag disappear, and all I have to do is "clean up" and I get the result I desire. I am curious if we can script the "clean up" part?

- However, the script does not de-flag Projects. It also does not de-flag tasks inside Projects that are flagged (auto-flagged tasks). Again, I am operating from context mode.

Do you have any additional suggestions on how I can achieve a full de-flagging of all objects in a given context/perspective?

Thank you! RT

RobTrew 2012-01-23 04:33 PM

Thanks for pointing that out.

Amended above, and should now clear project flags from Context view as well.

RobTrew 2012-01-26 01:57 PM

Further amended above - thanks to some very thoughtful and ingenious debugging by whpalmer4.

All times are GMT -8. The time now is 02:13 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.