This example demonstrates how to use the @paperline/node-accessibility package for macOS Accessibility API integration.
-
Install the package (from the root of the node-accessibility repository):
cd examples/basic-usage npm install -
Build the main package (if not already built):
cd ../.. pnpm run build
npm start
# or
npx tsx index.tsnpm run devThe example includes 7 different accessibility scenarios:
- Check if accessibility permissions are currently granted
- Provide guidance for requesting permissions
- Show the system dialog for permissions
- Handle immediate response (may require app restart)
- Show the system dialog and wait for permissions
- Handle timeout scenarios gracefully
- List all windows for iPhone Simulator
- Display window titles and count
- Focus the first available window
- Handle cases where no windows are available
- Focus a randomly selected window
- Demonstrate working with multiple windows
- Check windows for various common macOS apps
- Handle different application states
- ✅ Permission Management: Complete permission workflow
- ✅ Window Listing: List windows for any macOS application
- ✅ Window Focusing: Focus specific windows programmatically
- ✅ Multiple Apps: Work with different applications simultaneously
- ✅ Type Safety: Full TypeScript definitions and IntelliSense
- ✅ Async Support: Promise-based API with proper error handling
- ✅ Timeout Handling: Graceful timeout management
- ✅ Error Handling: Comprehensive error catching and user guidance
The example will demonstrate:
- Permission Status: Current accessibility permission state
- Permission Requests: System dialog interactions
- Window Listing: Available windows for various applications
- Window Focusing: Successful window focus operations
- Multi-App Support: Working with Finder, Safari, Simulator, etc.
- Error Handling: Graceful handling of missing apps or permissions
- macOS: Required for Accessibility API
- Node.js 16+: For running the example
- TypeScript: For type-safe development
- Accessibility Permissions: May need to be granted during first run
The example works with these applications:
- Finder:
com.apple.finder - Safari:
com.apple.Safari - iPhone Simulator:
com.apple.iphonesimulator - Terminal:
com.apple.Terminal
package.json- Example project configurationindex.ts- TypeScript example with 7 accessibility scenariosREADME.md- This documentation
