Browse the docs

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:

VariableWhat it holds
unsavedCountHow many windows have unsaved changes.
unsavedTitlesTheir titles, as a list.
unsavedTextA sentence for a question, such as 2 unsaved windows.

Parameters #

ParameterTypeRequiredValuesWhat it does
apptextA bundle identifier. Defaults to the front app.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Ask before quitting with unsaved work
When
  1. Before you quit TextEdit
Do
  1. Count the windows with unsaved changes in {{ app }}
  2. If {{ unsavedCount }} is above 0
  3. Ask “{{ unsavedText }}. Quit anyway?” with “Quit”
Open in Switchboard to try it

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