10.9 C
New York
Sunday, March 16, 2025

mail.app – AppleScript to Schedule Emails for Particular Date


I’m within the technique of writing a small Python Script to automate sending some emails that I ship each week, particularly each Monday at 8 AM. The Python script calculates when the following Monday will probably be, fills within the email template with the particular info, after which schedules it. I’ve been in a position to get the AppleScript to create the e-mail, put within the recipient, and put the signature, however I’ve not been in a position to get it to click on on the schedule to ship email button and schedule it for 8 AM. Right here is the present AppleScript I’ve:

 inform software "Mail"
        set theSender to "{sender_email}"
        set newMessage to make new outgoing message with properties {{topic:"Curiosity in {place} at {firm}", content material:"{email_body}", seen:true}}
        inform newMessage
            make new to recipient at finish of to recipients with properties {{deal with:"{recipient_email}"}}
            set sender to theSender
        finish inform
    finish inform

    inform software "System Occasions"
        inform course of "Mail"
            set frontmost to true
            inform window "Curiosity in {place} at {firm}"
                click on pop up button "Signature:"
                delay 0.5
                click on menu merchandise "AccountName" of menu of pop up button "Signature:"
                
                -- Await UI to replace
                delay 1
            finish inform
            
            -- Entry the menu instantly by menu bar merchandise title
            -- This makes use of precise menu hierarchy: Message menu > Ship Later...
            inform menu bar 1
                inform menu bar merchandise "Message"
                    inform menu "Message"
                        click on menu merchandise "Ship Later..."
                    finish inform
                finish inform
            finish inform
            delay 1
            
            -- Within the schedule dialog that seems
            inform sheet 1 of window "Curiosity in {place} at {firm}"
                set worth of textual content discipline 1 to "{next_monday_formatted}"
                set worth of textual content discipline 2 to "8:00 AM"
                click on button "Schedule"
            finish inform
        finish inform
    finish inform

All the things works however the scheduling half, and that is the final try I’ve made. I do know that there are email automation instruments, however I wish to discover ways to code this on my own and combine it into the terminal. Any assist could be appreciated, thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles