I was looking at my Forecast view in OmniFocus this morning, and the list was fully expanded. Because I use defer dates a lot, the expanded Forecast can look pretty intimidating. I can never remember the key command to collapse and expand, so I end up manually doing it in the GUI. I thought this might be a good use of AppleScript, especially since OmniFocus has a scripts folder that you can use to store scripts and then drag them into the toolbar.
I asked ChatGPT to write a script to first collapse, and then another to expand, and then realized I should ask it to make the script toggle the state based on whatever state is currently active:
tell application "OmniFocus" tell front document tell content of front document window set theTrees to trees if theTrees is not {} then set firstTreeExpanded to expanded of item 1 of theTrees set newState to not firstTreeExpanded -- Toggle based on the current state of the first tree repeat with aTree in theTrees set expanded of aTree to newState end repeat end if end tell end tell end tell
Here’s what it looks like:
applescript-of-expand-collapse.mp4
It’s in the toolbar too: