I am running python on a Mac and am attempting to send a notification that when clicked, will open a folder stored on the desktop. Below is my code with print statements to aid troubleshooting.:
import os
import platform
desktop_dir = os.path.join(os.path.expanduser("~"), "Desktop")
SaveLocation = os.path.join(desktop_dir, "my Schedules")
if platform.system() == 'Darwin': # macOS
from pync import Notifier
print("sending notification")
Notifier.notify('Your files are ready. Click to view.',
title='my Schedule Generator',
sound=True, # Optional sound
open = SaveLocation) # This makes the notification clickable
print("file opened")
Notifier.notify('website link', open='http://github.com/', title = "titling")
the output in my terminal shows that all print statements are printed and the last line of code (below) works without any problems (shows up and opens link when clicked on).
Notifier.notify('website link', open='http://github.com/', title = "titling")
My issue is that the if
statement does not generate a notification.
If you look at the documentation for pync on Pypi.org and try the example that includes the open keyword you'll notice that it doesn't work. Note that pync hasn't been updated since 2018 which probably suggests that it's incompatible with current macOS versions.
If you want to open a file from a notification you could do this:
from pync import Notifier
# the file to be opened
FILE = __file__
Notifier.notify("Check this out", execute=f'open "{FILE}"')