Count unsaved windows
Counts the windows of an app that have unsaved changes, for a guardrail that asks before you quit.
Count unsaved windows of app
Details #
Reads the app's windows through Accessibility and counts the ones that report unsaved changes (the dot in the red close button). With no app it reads the front app, which is the app a Before a key, click or quit guardrail is guarding.
The step leaves these variables:
| Variable | What it holds |
|---|---|
unsavedCount | How many windows have unsaved changes. |
unsavedTitles | Their titles, as a list. |
unsavedText | A sentence for a question, such as 2 unsaved windows. |
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
app | text | A bundle identifier. Defaults to the front app. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
Ask before quitting with unsaved work
When
- Before you quit TextEdit
Do
- Count the windows with unsaved changes in {{ app }}
- If {{ unsavedCount }} is above 0
- Ask “{{ unsavedText }}. Quit anyway?” with “Quit”
Gotchas #
Only apps that report unsaved changes to Accessibility are counted. An app that draws its own windows reports none.
Dry run. Nothing is read. The step answers with one sample window.
See also #
Before a key, click or quit, Ask Send anyway? (guardrail), Guardrails: check before it happens