apps — which applications are running, and who has focus
apps is the observation tool you reach for before anything else: it
answers “what is running?” and — with one query — “where do my keystrokes go
right now?”. It never synthesizes input, so it is safe in every permission
mode.
Computer::apps(&self, input: &ComputerApps) -> Result<AppsResult, String>
apps(metadata, ComputerApps) -> Result<AppsResult, String> // free function
The two queries
target: "all"(default) — a point-in-time enumeration of running applications: name, PID (when the platform reports one), and which entry holds the system foreground. Enumeration order is the platform’s; theforegroundflag is the stable fact.target: "focused"— resolves the foreground application and the element inside it holding keyboard focus. This is the cheap ground truth the input tools previously guessed at: before typing, CHECK the focused element instead of assuming the last click landed.timeout_msbounds the wait for a foreground app to exist at all.
Reading the result
The result is the untagged enum AppsResult — the
variant follows the query:
AppsResult::All(AppsOutput)—apps: Vec<AppInfo>+count;AppsResult::Focused(FocusedOutput)— the foreground app’sname/pidplusfocused_element: Option<FocusedElement>. TheOptionmatters: focus may sit on the window itself (no element), or the platform may not report element focus. TreatNoneas “keystrokes go to the window, not a named field”.
Edges
- Focus is a moment. Between the
focusedquery and your next call the user may click elsewhere. For input that must land in a specific field, prefer a real click (control) over assuming focus persists. - PIDs can be absent on some backends; never build logic that requires
them. Scope other tools by
namewhen possible.
See also
snapshot for the tree below the focused element ·
runnable example: cargo run --example computer-apps