Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karaggeorge/mac-screen-capture-permissions
Check and request permission to capture the screen
https://github.com/karaggeorge/mac-screen-capture-permissions
Last synced: 12 days ago
JSON representation
Check and request permission to capture the screen
- Host: GitHub
- URL: https://github.com/karaggeorge/mac-screen-capture-permissions
- Owner: karaggeorge
- Created: 2019-11-06T00:29:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T19:10:05.000Z (about 1 year ago)
- Last Synced: 2024-10-23T07:18:28.104Z (19 days ago)
- Language: JavaScript
- Size: 591 KB
- Stars: 117
- Watchers: 2
- Forks: 35
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# mac-screen-capture-permissions
> Check and request permission to capture the screen on macOS (introduced with 10.15 Catalina)
## Install
Building the module from source requires macOS 11+ SDK, but the resulting module will still run on <10.15, 10.15 and 11+.
```
$ npm install mac-screen-capture-permissions
```## Usage
See [example.js](https://github.com/karaggeorge/mac-screen-capture-permissions/blob/master/example.js) for usage.
```js
const {
hasScreenCapturePermission,
hasPromptedForPermission
} = require('mac-screen-capture-permissions');hasPromptedForPermission();
// false
hasScreenCapturePermission();
// false
hasPromptedForPermission();
// true
// After accepting the permissions
hasScreenCapturePermission();
// true
```## API
#### `.hasScreenCapturePermission(): boolean`
Whether or not the current app has the required permissions to record the screen. If this is the first time attempting, a permissions dialog will be shown to the user. Any subsequent calls to `hasScreenCapturePermission` will just check for the permission but won't show a dialog. If the user denied the original request, you need to prompt them to enable the permissions in the System Preferences.
This can be reset by calling `resetPermissions`. The dialog will be shown again after that.
Returns `true` on macOS versions older than 10.15 since this permission wasn't present
#### `.hasPromptedForPermission(): boolean`
**Note:** Only works for Electron apps
Whether or not the permission dialog has been shown to the user. Will be `false` if you haven't called `hasScreenCapturePermission` for this app yet, and `true` otherwise.
This can be reset by calling `resetPermissions`,
Returns `false` on macOS versions older than 10.15 since this permission wasn't present
#### `.resetPermissions({bundleId?: string}): boolean`
Reset the `ScreenCapture` permissions. It will reset the permissions for **all** apps, so use with care. Provide a `bundleId` (i.e. com.apple.Terminal) to reset the permissions only for that app.
Calls `tccutil reset ScreenCapture [bundleId]`.
This will revoke access if it was previously granted, and it will trigger the permissions dialog the next time `hasScreenCapturePermission` is called.
Returns `true` if the command executed successfully and `false` otherwise.
Returns `false` on macOS versions older than 10.15 since this permission wasn't present
#### `.openSystemPreferences(): Promise`
Open the System Preferences in the Screen Recording permissions section under the Security pane.
Only available in Electron apps.
Returns a Promise that resolves when the window is opened
## License
MIT