From python I'd been triggering notifications like this:
def show_alert(message, title="Flashlight"):
"""Display a macOS notification."""
message = json.dumps(message)
title = json.dumps(title)
script = 'display notification {0} with title {1}'.format(message, title)
os.system("osascript -e {0}".format(pipes.quote(script)))
but now I want to be able to trigger these alerts some time in the future.
I had a method using time
, time.sleep(60)
would trigger an alert a minute in the future.
The problem with that is that if the script is ended, or the computer sleeps, I'm not sure how realiable it would be.
Is there a way I can use python (maybe with applescripts, or other macOS tools) to schedule a notification for some arbitrary time in the future?