Using Apples Information Property List Files (Info.plist) in Python on MacOS
-
wrote on 7 Sept 2022, 08:38 last edited by
Hi at all,
I am in the process of developing an application in python under macos that should use bluetooth. But already when I try to use the QBluetoothDeviceDiscoveryAgent I get an error message regarding an entry in the Info.plist.
I read that an NSBluetoothAlwaysUsageDescription entry would be required in this file. And I also saw that on apple systems, this file is normally managed by xcode and will be included in the compiled package. But my program is written in python and there is no compiled package and I don't use xcode.
Please, can someone give me a tip on how to do this?
-
wrote on 7 Sept 2022, 09:04 last edited by
The plist file is just a text file filled with the necessary data and put into the application bundle.
So basically you could use a template/create one yourself with the keys and just copy it to the final bundle. On c++ qt with CMake you can create the plist file during build however I have no clue how to do that with python as I don't use it.
What might also interfere with your Bluetooth use is the lack of an proper entitlement for your app. The Bluetooth usage description might be enough but if your app crashes on start you might be missing the Bluetooth entitlement. If you don't have Xcode available it might get tedious. -
wrote on 7 Sept 2022, 12:23 last edited by
I don't understand it anyway. For example, when I use bleak, a Python library for Bluetooth Low Energy, and run a scan there, I am asked if the application (the terminal in that case) is allowed to use Bluetooth.
Then the terminal app as the caller is entered as Allowed in the settings under Security & Privacy / Bluetooth. And then it works. But this setting doesn't seem to apply to Python Qt and its QBluetoothDeviceDiscoveryAgent.But since bleak uses asyncio and that is problematic under Qt, I thought it would be easier to use Qt's Bluetooth modules.
-
wrote on 7 Sept 2022, 19:39 last edited by
I just ran the c++ BT scanner example without problems on my M1 Mac.
Here is the Info.plist that is in the compiled file. Maybe it will work for you as well:<?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>CFBundleExecutable</key> <string>btscanner</string> <key>CFBundleIconFile</key> <string></string> <key>CFBundleIdentifier</key> <string>${PRODUCT_BUNDLE_IDENTIFIER}</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> <key>LSMinimumSystemVersion</key> <string></string> <key>NSPrincipalClass</key> <string>NSApplication</string> <key>NSBluetoothAlwaysUsageDescription</key> <string>Qt BT Example wants to access your Bluetooth adapter</string> <key>NSSupportsAutomaticGraphicsSwitching</key> <true/> </dict> </plist>
Obviously some entries are not entirely valid but I don't get any problems running locally.
-
wrote on 8 Sept 2022, 12:16 last edited by
After several hours of searching the Internet, I have come to the conclusion that I am not on the right way.
As I wrote above, the first time I use Bluetooth using the bleak modul, I am asked if I want to allow access. When using the QBluetoothDeviceDiscoveryAgent there is no request.
While searching the internet, I found a post where someone had similar problems accessing the video camera. It said, that the manufacturer of the module is responsible for announcing it to the operating system before accessing corresponding components (video, bluetooth). And then the os dialog would appear asking the user for approval. Bleak apparently does that. Of course, I don't know if all this is correct, but it sounds right at first.
The way via an info.plist apparently only works if you create an app. This would also be possible with python, but not in the development phase.I even found a description of how to create a suitably legitimized python interpreter app, which then launches the script. But that sounded pretty complicated.
I can't believe that should be so complicated. After all, Qt offers the QBluetoothDeviceDiscoveryAgent module explicitly for Python.
-
After several hours of searching the Internet, I have come to the conclusion that I am not on the right way.
As I wrote above, the first time I use Bluetooth using the bleak modul, I am asked if I want to allow access. When using the QBluetoothDeviceDiscoveryAgent there is no request.
While searching the internet, I found a post where someone had similar problems accessing the video camera. It said, that the manufacturer of the module is responsible for announcing it to the operating system before accessing corresponding components (video, bluetooth). And then the os dialog would appear asking the user for approval. Bleak apparently does that. Of course, I don't know if all this is correct, but it sounds right at first.
The way via an info.plist apparently only works if you create an app. This would also be possible with python, but not in the development phase.I even found a description of how to create a suitably legitimized python interpreter app, which then launches the script. But that sounded pretty complicated.
I can't believe that should be so complicated. After all, Qt offers the QBluetoothDeviceDiscoveryAgent module explicitly for Python.
wrote on 30 Jun 2023, 21:11 last edited by@WolleKette
Hi, did you ever find a solution to this? I'm running into the same issue. -
wrote on 30 Sept 2023, 18:03 last edited by
I have the same exact issue right now.
PySide6 devs are blaming Cpython for this and they suggested re-building Cpython for scratch with cusotm info.plist. This looks tedious to me.
https://bugreports.qt.io/browse/PYSIDE-2474