-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'NoneType' object has no attribute 'setDelegate_' #8
Comments
Exact same error, Python 3.10.10 (conda), macOS 13.4. |
I googled quite briefly and as the README suggests, the current method of using NSUserNotificationCenter is deprecated and only supported up to MacOS 11.0, see here. The new way to do it is via UNUserNotificationCenter, but it seems that it is only available when run from a signed binary (?) I just tried myself to get UNUserNotificationCenter to work but it's a mess and hard to get working lol |
I have figured out a way to send notifications, but it's not pretty at all and goes against the point of this library, which is "mac-notification is a Python library to make it as easy as possible to create interactable notifications." Here's the code though: from Cocoa import NSApplication, NSClassFromString
def main():
center = NSClassFromString("UNUserNotificationCenter")
print(center)
current = center.currentNotificationCenter()
print(current)
if __name__ == "__main__":
main() However, if you just run this from a script, it will crash with the exception pip3 install py2app
echo -e "[tools.py2app.bundle.main]\nscript = "main.py"\nbuild-type = "semi-standalone" > pyproject.toml
py2applet --make-setup main.py
./dist/notif.app/Contents/MacOS/notif This code should give you something like I wonder if Jorricks can find a way to send notifications simper than this, but it seems it's a fundamental problem put on by Apple themselves :( |
Sorry for dropping the ball on this one. Have any of you been able to figure this issue out? |
I have posted all my findings above. As I said, I think it is fundamentally impossible to post notifications from an unsigned app alone. However, if you can launch a signed service in the background once, then you can make it send the notifications for you, kind of like a proxy. Hope my terminology is ok |
Same issure here. |
Sorry for replying this late and thanks for reporting this. I have the feeling this is because of not using the official python binary. If you use a self-compiled Python binary that is not officially signed by an Apple certificate, it will throw this error. Could you try with an official Python binary and report back here? Would you mind giving this a shot @MacHu-GWU and @grhkm21 ? |
@Jorricks I am python 3.12 installed with home-brew on Ventura. And it's official binary which works for all apple api access like photos, notes etc. But giving me the same error when using action. Simple notifications are working though. |
Could you try with a version downloaded and installed from https://www.python.org/downloads/? |
@Jorricks that makes a lot of sense. Then this library has to be used as a agent. For example, If I use pyenv to manage python and most of my application code are running in pyenv python. I need to create a simple script that uses system python and add your library to the path. Then my application code should use the subprocess module to run that script to send a notification (the subprocess looks like Am I right? |
Yes that's my theory at least. Would be nice if you could validate it. |
I tried, but it doesn't show the notification as well. I figured out the issue. I installed another python notification library desktop-notifier. And after creating a simple script to fire notification, the prevoius script which uses this library stops working until I reset notification settings for Python in Settings-> Notifications (by right clicking->reset). After reseting, and giving permission again, it works. The moment I use desktop-notifier it stops working. What could be the issue? I am guessing issue is python being common name here? Even though desktop-notifier allows to set an app name, I have to allow for python and not app name. |
Python 3.11.3, "client.create_notification" returns the following error:
Process NotificationProcess-1: Traceback (most recent call last): File "/Users/rutger/.pyenv/versions/3.11.3/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap self.run() File "/Users/rutger/.pyenv/versions/3.11.3/lib/python3.11/site-packages/mac_notifications/listener_process.py", line 28, in run notification_sender.create_notification(self.notification_config, self.queue).send() File "/Users/rutger/.pyenv/versions/3.11.3/lib/python3.11/site-packages/mac_notifications/notification_sender.py", line 58, in send NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'setDelegate_'
The text was updated successfully, but these errors were encountered: