Step 1: Configure Xcode to find the app bundle

Each time you build and run your project in Xcode, it creates a new application bundle. The location can be randomized, which makes granting a persistent permission difficult. To fix this, you should set a consistent build location.
- With your project open, select File > Project/Workspace Settings from the menu bar.
- Under the Derived Data section, change the build location to "Workspace-relative location".
- Click Done.
Step 2: Grant Accessibility permission in System Settings
After you have configured your build path, run your app at least once from Xcode. This creates the app bundle that you will now grant permission to.
- Open System Settings (or System Preferences on older macOS versions).
- Navigate to Privacy & Security > Accessibility.
- Click the padlock icon at the bottom and enter your password to make changes.
- Click the + button under the list of applications to add a new app.
- In the file browser that appears, navigate to your project's directory. Go to
DerivedData/YourProjectName/Build/Products/Debug/.
- Select your application bundle (e.g.,
YourAppName.app) and click Open.
- Find your app in the list and ensure the checkbox next to it is checked.
- Restart your app from Xcode, and it should now have the necessary permissions.