That's understandable. This modified version should work in 1.7 as well as in 1.8
It acts as a toggle, flipping back and forth, with each successive run/click, between either releasing the filter and focus, or focusing on just projects which are not on-hold.
Code:
-- Toggle between no focus and focus on filtered subset (in view with Grouping=Filter)
property pstrFilter : "where (status is not on hold) and ((effectively hidden of its folder is false) or (its folder is missing value))"
property pLibraryTree : 2
property pstrNewScript : "
script
on GetProjects(oDoc)
using terms from application \"OmniFocus\"
return flattened projects of oDoc " & pstrFilter & "
end using terms from
end GetProjects
end script
"
property pstrOldScript : "
script
on GetProjects(oParent)
using terms from application \"OmniFocus\"
tell oParent
-- ADJUST THE WHERE QUERIES TO MATCH THE PURPOSE
set lstProjects to projects " & pstrFilter & "
set lstFolders to folders
end tell
repeat with oFolder in lstFolders
set lstProjects to lstProjects & my GetProjects(oFolder)
end repeat
return lstProjects
end using terms from
end GetProjects
end script
"
tell application id "com.omnigroup.OmniFocus"
set oDoc to default document
set oWin to front document window of oDoc
tell oWin
if selected view mode identifier of oWin is not "project" then ¬
set selected view mode identifier to "project"
end tell
if my IsNarrowed(focus of oWin) then
set focus of oWin to {}
else
if build number ≥ "77.57.0.134152" then
set oScript to run script pstrNewScript
else
set oScript to run script pstrOldScript
end if
set lstProjects to GetProjects(oDoc) of oScript
tell oWin
set focus to lstProjects
set selected grouping identifier of content to "folder"
end tell
end if
tell sidebar of oWin
--set selected smart group identifier to "all-projects"
select tree pLibraryTree
end tell
end tell
-- Detect whether the sidebar has a narrowed focus
on IsNarrowed(oFocus)
repeat with oObj in oFocus
return true
end repeat
return false
end IsNarrowed