---
title: "Enable AT-SPI accessibility in a C# desktop app"
url: https://recursiveai.org/oneapp/cookbook/enable-linux-at-spi-in-desktop-app/
description: "Turn on OneApp’s Linux accessibility bridge and use an AT-SPI client to inspect the role and name of a button in a running C# desktop app."
version: "1.1.1"
---

The sample has one button, Save note. On Linux, set `AccessibilityMode.On` to expose it through AT-SPI, the interface screen readers such as Orca use. On desktop, OneApp runs on [Linux (Wayland and X11), macOS (Apple silicon), and Windows](https://github.com/recursive-ai-oss/oneapp-csharp/blob/b93a90dc510817e92a4ebd1e340b83118461665c/README.md#L62-L68).

The accessibility bus comes from `at-spi2-core` and is normally available in GNOME or KDE sessions. On Xvfb, we used `dbus-run-session` so D-Bus could start `org.a11y.Bus` on demand.

```shell
dotnet add package RecursiveAI.OneApp
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneApp;

using var host = AppHost.Create(
    new AppOptions(
        "<button>Save note</button>")
    {
        Title = "Accessible Notes",
        Accessibility = AccessibilityMode.On
    });
host.AccessibilityStatusChanged += status =>
    Console.WriteLine(status.State);
host.Run();
```

Checked on Linux (X11), when the bridge connects:

```text
Active
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/oneapp/cookbook/enable-linux-at-spi-in-desktop-app/enable-linux-at-spi-in-desktop-app.zip) and `dotnet run`.

Keep the window open. In a second terminal in the same graphical session, run the included `inspect_button.py` with Python 3, PyGObject and the AT-SPI introspection bindings installed (`python3-gi` and `gir1.2-atspi-2.0` on Debian or Ubuntu):

```shell
python3 inspect_button.py
```

The script reads a live accessible object, not the HTML file:

```python
import gi
import time

gi.require_version('Atspi', '2.0')
from gi.repository import Atspi


def find(node):
    is_button = (node.get_role() ==
                 Atspi.Role.PUSH_BUTTON)
    if is_button:
        if node.get_name() == 'Save note':
            return node
    count = node.get_child_count()
    for index in range(count):
        child = node.get_child_at_index(index)
        if child and (match := find(child)):
            return match
    return None


Atspi.init()
for _ in range(20):
    button = find(Atspi.get_desktop(0))
    if button:
        role = button.get_role_name()
        print(f'{role}: {button.get_name()}')
        break
    time.sleep(0.25)
else:
    raise SystemExit('Button not found')
```

With English role names, the client prints:

```text
button: Save note
```

If the bridge reports `Unavailable`, read `host.AccessibilityStatus.Reason` to distinguish a missing session or accessibility bus from a connection failure. Setting `On` doesn’t create those buses.

## Variations

For normal desktop use, let the desktop signal when it wants the bridge by changing the `Accessibility` setting in `Program.cs`:

```csharp
Accessibility = AccessibilityMode.Auto
```

`Auto` is the default. It can stay in `Waiting` until the desktop enables accessibility; use `On` to check what the app exports without relying on that preference.

## Related recipes

- [Build a desktop app with HTML and CSS in C#](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Open a second window in a C# desktop app](https://recursiveai.org/oneapp/cookbook/open-second-window-in-desktop-app/)

## The short answer

Set `AppOptions.Accessibility` to `AccessibilityMode.On` when creating the host. Keep `host.Run()` active and inspect the window from an AT-SPI client in the same Linux session. An active bridge confirms the connection; finding `button: Save note` confirms the role and name the client can actually read.

## How do I turn on accessibility mode in a Linux app?

Use `Auto` if the app should follow the user’s desktop accessibility settings. In this mode OneApp watches the desktop’s `IsEnabled` and `ScreenReaderEnabled` flags and registers once either is true. `On` registers whenever the accessibility bus is available. `Off` doesn’t connect at all. These settings control what the app exports; they don’t start a screen reader or change anyone’s desktop preference.

Read the status after the event loop has had a chance to connect. Logging `AccessibilityStatusChanged` on the UI thread shows transitions instead of taking a single snapshot right after startup. In a desktop session where the accessibility bus is missing, you can still see the app window, but the client won’t see the exported controls.

## How can I tell what a screen reader sees on Linux?

Inspect the live tree, not just the markup. OneApp exports windows and their page trees with roles, names, descriptions and states. The example uses a real `<button>` so its role comes from the element and its visible text supplies its name. The script walks the desktop tree, matches both role and name, and prints the match. For a fuller inspection, use an interactive AT-SPI client and open your app’s window node to see its controls.

A matching name and role is a useful first check, not a guarantee that a whole view is usable. For a form, also inspect the names of controls without visible text, watch focus move as you tab, and check that each control has the state you expect when it’s disabled or selected. The [OneApp accessibility docs](https://recursiveai.org/oneapp/docs/accessibility/) list the events and actions exported by the bridge.
