Search code examples
swiftxcodemacosprivacy

Mac OS: Remember Security & Privacy options for app while developing


I am developing a Mac OS app that accesses information like capturing the computer screen or controlling the mouse. (The app is just for personal use)

This works fine in the beginning. When my app tries to access a feature, I get asked to allow this in the system preferences (See dialog below) and if I do so, I can access the content. And as long as I don't change anything in my code I can rerun the app as often as I want and the permissions stay intact.

My issue is that every time I change something in the code, I also need to grant the permissions again to the app. Can someone please help me and explain why and what I can do to prevent this?

Mac OS: Catalina 10.15.7

Thanks so much for the help!

enter image description here


Solution

  • So even if it seems that you actually have to uncheck and check the box in the privacy settings over and over again, this doesn't mean you have to do it yourself all the time.

    What helped me is recording an Automator workflow that checks the boxes for me. You can then run this workflow in a build phase to run it on every build.

    Steps:

    1. Open the window for the Security & Privacy settings
    2. Open automator
    3. Create a new workflow
    4. Click the red record button at the top right (You might need to whitelist Automator in the Security & Privacy settings as well)
    5. Record the steps that you normally do to enable the Privacy for your app (uncheck/check the respective box)
    6. End the recording in automator and run the workflow once to ensure it works
    7. Set the Automator workflow playback speed to the max (10x) to speed things up, also set the timeout to 0
    8. Save the automator workflow to the disk
    9. In Xcode click on your Target and switch to the 'Build Phases' tab
    10. Click the '+' > 'New Run Script Phase'
    11. Add the following shell script (Replace the path with the path to your Automator workflow file) /usr/bin/automator ~/MyFolder/MyWorkflow.workflow
    12. You might need to whitelist Automator in the Security & Privacy settings under 'Accessibility' as well

    You will need to leave the Security & Privacy settings window open if you didn't include a step in your workflow to actually open it beforehand.

    Now when you build/run the app the Automator script should do the work for you and the Privacy settings should be setup correctly.