I am in the process of writing a small Python Script to automate sending some emails that I send every week, specifically every Monday at 8 AM. The Python script calculates when the next Monday will be, fills in the email template with the specific information, and then schedules it. I have been able to get the AppleScript to create the email, put in the recipient, and put the signature, but I have not been able to get it to click on the schedule to send email button and schedule it for 8 AM. Here is the current AppleScript I have:
tell application "Mail"
set theSender to "{sender_email}"
set newMessage to make new outgoing message with properties {{subject:"Interest in {position} at {company}", content:"{email_body}", visible:true}}
tell newMessage
make new to recipient at end of to recipients with properties {{address:"{recipient_email}"}}
set sender to theSender
end tell
end tell
tell application "System Events"
tell process "Mail"
set frontmost to true
tell window "Interest in {position} at {company}"
click pop up button "Signature:"
delay 0.5
click menu item "AccountName" of menu of pop up button "Signature:"
-- Wait for UI to update
delay 1
end tell
-- Access the menu directly through menu bar item name
-- This uses exact menu hierarchy: Message menu > Send Later...
tell menu bar 1
tell menu bar item "Message"
tell menu "Message"
click menu item "Send Later..."
end tell
end tell
end tell
delay 1
-- In the schedule dialog that appears
tell sheet 1 of window "Interest in {position} at {company}"
set value of text field 1 to "{next_monday_formatted}"
set value of text field 2 to "8:00 AM"
click button "Schedule"
end tell
end tell
end tell
Everything works but the scheduling part, and this is the last attempt I have made. I know that there are email automation tools, but I want to learn how to code this by myself and integrate it into the terminal. Any help would be appreciated, thanks!