Skip to content

Add hs.application.hideOtherApplications() function#3863

Open
jake-edmonstone wants to merge 1 commit intoHammerspoon:masterfrom
jake-edmonstone:add-hideOtherApplications
Open

Add hs.application.hideOtherApplications() function#3863
jake-edmonstone wants to merge 1 commit intoHammerspoon:masterfrom
jake-edmonstone:add-hideOtherApplications

Conversation

@jake-edmonstone
Copy link
Copy Markdown

@jake-edmonstone jake-edmonstone commented Apr 8, 2026

Summary

Adds hs.application.hideOtherApplications() — a module-level function that hides all applications other than the frontmost one.

This calls [[NSWorkspace sharedWorkspace] hideOtherApplications] directly, providing the programmatic equivalent of Cmd+Opt+H (Hide Others).

Motivation

Currently, hiding all other applications requires either:

  • Simulating a keystroke with hs.eventtap.keyStroke({"cmd", "alt"}, "h") — works but is indirect
  • Iterating hs.application.runningApplications() and calling app:hide() on each — has race conditions with Safari Web Apps and is slower

A direct API call is cleaner, faster, and avoids edge cases with keystroke simulation.

Usage

-- Switch to an app and hide everything else
local app = hs.application.get("com.mitchellh.ghostty")
app:activate(true)
hs.application.hideOtherApplications()

Implementation

  • Single function addition to extensions/application/libapplication.m
  • Registered in the moduleLib table (module-level function, not instance method)

Add a module-level function that hides all applications other than the
frontmost one by calling `[[NSWorkspace sharedWorkspace] hideOtherApplications]`.

This is the programmatic equivalent of Cmd+Opt+H (Hide Others) and provides
a direct API for window management workflows that need to isolate a single
application, without resorting to keystroke simulation via `hs.eventtap` or
iterating all running applications.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: ['pr-fix', 'pr-change', 'pr-feature', 'pr-maintenance']

@jake-edmonstone jake-edmonstone marked this pull request as ready for review April 8, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant