Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karaggeorge/mac-focus-window
Focus a window and bring it to the front on macOS
https://github.com/karaggeorge/mac-focus-window
Last synced: 21 days ago
JSON representation
Focus a window and bring it to the front on macOS
- Host: GitHub
- URL: https://github.com/karaggeorge/mac-focus-window
- Owner: karaggeorge
- Created: 2019-11-27T22:06:10.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-24T21:05:05.000Z (almost 5 years ago)
- Last Synced: 2024-10-04T15:29:54.749Z (about 1 month ago)
- Language: Swift
- Size: 7.81 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# mac-focus-window
> Focus a window and bring it to the front on macOS
Requires [accessibility permissions](https://www.applegazette.com/mac/what-are-accessibility-permissions-all-about/).
Requires macOS 10.12 or later. macOS 10.13 or earlier needs to download the [Swift runtime support libraries](https://support.apple.com/kb/DL1998).
## Install
```
$ npm install mac-focus-window
```## Usage
```js
const focusWindow = require('mac-focus-window');if (focusWindow.isSupported && focusWindow.hasPermissions()) {
focusWindow(12345);// true
} else {
focusWindow.requestPermissions();
}
```## API
### `focusWindow(windowNumber: number | string): Boolean`
Focus the given window and bring it to the front.
An error will be thrown if:
- Accessibility permissions are not enabled for the current app
- You provide `windowNumber` as a string, but it's not a number
- There is no window with the given numberReturns `true` if the window was focused successfully, and `false` otherwise.
#### `focusWindow.isSupported`
Will be `true` if the module is supported (based on macOS version).
#### `focusWindow.hasPermissions(): Boolean`
Check if the current app has accessibility permissions. This will not prompt the user with the system dialog.
Returns `true` if the app has permissions, and `false` otherwise.
#### `focusWindow.checkPermissions(): Boolean`
Same as `hasPermissions`, but it will present the user with the native permissions dialog.
**Notes:**
- The permissions dialog will only be shown if the app doesn't have permissions
- The user has to go into the System Preferences to give access, so if the app doesn't have permissions, this will return `false` immediately after presenting the dialog. You have to check again after the user has granted the permissions for this to be `true` (restart of the app not required)## Related
- [mac-window-select](https://github.com/karaggeorge/mac-window-select) - Prompt the user to select a window on macOS, mimicking the native screenshot utility
- [mac-windows](https://github.com/karaggeorge/mac-windows) - Provide Information about Application Windows running## License
MIT