Created
May 16, 2023 19:16
-
-
Save kalyan02/634b84cca2fb1e78f60a9343ede8861d to your computer and use it in GitHub Desktop.
Python script to show alert when a meeting is starting in 1 min
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import datetime | |
import time | |
minutes=2 | |
calendar_name = "Home" | |
def run_applescript(script): | |
osa_command = ['osascript', '-e', script] | |
return subprocess.run(osa_command, capture_output=True, text=True).stdout | |
def check_meetings(calendar_name, minutes): | |
script = f""" | |
tell application "Calendar" | |
tell (first calendar whose name is "%s") | |
get the summary of (every event whose start date is greater than (current date) and start date is less than (current date + %d * minutes)) | |
end tell | |
end tell | |
""" % (calendar_name, minutes) | |
events = run_applescript(script).strip().split(", ") | |
print(events) | |
if events[0] != "": | |
alert_script = f""" | |
display dialog "Meeting is starting: {', '.join(events)}" | |
""" | |
run_applescript(alert_script) | |
while True: | |
check_meetings(calendar_name, minutes) | |
time.sleep(minutes*60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment