python access /Library on macos

Question:

I am trying to write an install file to the /Library folder if the user doesn’t have it. I can run the code in "sudo python …" and it works.

However using pyinstaller and creating a packaged app gives me an Error 13 permission denied.

[Errno 13] Permission denied: ‘/Library/…’)

Is there a key value in Info.plist to grant full access to files? I have manually added full disk access to the app without luck. What are the necessary security measures needed to be able to get this to run?

Here is the Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>correction</string>
    <key>CFBundleExecutable</key>
    <string>correction</string>
    <key>CFBundleIconFile</key>
    <string>icon-windowed.icns</string>
    <key>CFBundleIdentifier</key>
    <string>com.me.correction</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>correction</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>0.0.0</string>
    <key>NSCameraUsageDescription</key>
    <string>Access Camera</string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSSystemAdministrationUsageDescription</key>
    <string>Install Files For Driver</string>
</dict>
</plist>
Asked By: msj121

||

Answers:

If you want to run a program with root privs without a terminal command line, you can do so via Applescript.

If the script doesn’t need a tty, this will work:

do shell script "python /path/to/your/python/script" with administrator privileges

If you Export that as an Application from Script Editor, you’ll get a double-clickable app that will pop up a dialog to get the user’s password/fingerprint and then run your Python code as root.

Answered By: Mark Reed