Question

I am writing a script for my school's pickup system. Is there a way to make my applescript trigger when i get a Gmail? I have tried hooking it up with IMAP to mail.app and making a rule that triggers it, but even if i get the emails, my mail rule doesn't trigger. Any suggestions? P.S. Please don't use any coding or applescript mumbo-jumbo lingo in your answers, I'm sort of an amateur at this.

##define procedure to edit googledoc
on writeToTheGoogleDoc(listContent)
##Edit the Google Document
set studentClass to (item 3 of listContent)
tell application "Google Chrome" to activate
tell application "System Events"
    tell process "Google Chrome"
        ##open a new window
        keystroke "n" using command down
        ##open the correct google doc according to which class student is in
        if studentClass = "6A" then
            keystroke "https://docs.google.com/document/d/1qYeDyVwggR0nzH7YURsjS1pGx03kSwfkDz2DFiNYETY/edit"
        else if studentClass = "6B" then
            keystroke "https://docs.google.com/document/d/1lyTg9CZdQUcpoc8QOl592nNdQiFH_GTLvRtGeDeUSII/edit"
        else if studentClass = "7A" then
            keystroke "https://docs.google.com/document/d/1_njYvXfDZHpx7OFAHTnfpfyO0R2476gxFxjl9m2QMLc/edit"
        else if studentClass = "7B" then
            keystroke "https://docs.google.com/document/d/1g951YT5M4VOee-kuOK4TqstiQqozU5FyhcaHUUJJmHM/edit"
        else if studentClass = "8A" then
            keystroke "https://docs.google.com/document/d/1fhCmMRSPCfmXOimyd2pnR273k8Ykzio4x_3S28dPAMQ/edit"
        else if studentClass = "8B" then
            keystroke "https://docs.google.com/document/d/1gWmEKdjJIBnLzaC1_m3obIzhM2mlUeOxEXVRkGzcPiM/edit"
        end if
        ##press return so the webpage will load, wait for it to load
        keystroke return
        delay 3
        ##write the text to the opened google doc
        set messageToBePosted to (item 1 of listContent) & ": PICKUP BY " & (item 2 of listContent)
        keystroke messageToBePosted
        ##press return so next message will be on a new line
        keystroke return
        ##wait so the google doc has time to commit changes
        delay 2
        ##close the window
        keystroke "w" using command down
    end tell
end tell
end writeToTheGoogleDoc
##run the procedure
set contentList to {}
tell application "Mail"
    set carpoolMessages to (get every message of mailbox "CARPOOL" whose subject contains "CARPOOL")
repeat with eachMessage in carpoolMessages
    set end of contentList to (content of eachMessage)
end repeat
end tell
repeat with eachContent in contentList
set AppleScript's text item delimiters to ":"
set theContentList to every text item of eachContent
set item 3 of theContentList to (text 1 thru 2 of item 3 of theContentList)
writeToTheGoogleDoc(theContentList)
delay 0.5
end repeat
Était-ce utile?

La solution

Did you include the mail rule handler in your script? It's always better to share the code or part of your code that isn't working to help and understand the problem better. It's now like "my car won't start" and we have to guess what could be wrong.

There are however some parts that are important to work properly:

1- Did you include the perform mail action with messages handler? This handler, or in this case event, must be included to the script, it's starting event for the mail rule to trigger inside your script. It doesn't run your script when an script is set as an mail rule action.

using terms from application "Mail"
    on perform mail action with messages message_list in mailboxes mbox for rule a_rule
        tell application "Mail"
            display dialog "You've got " & (count of message_list) & " new mails"
        end tell
    end perform mail action with messages
end using terms from

3- In Mountain Lion and higher the script needs to be saved in the ~/Library/Application Scripts/com.apple.mail folder to work.

There are AppleScript mail rule issues in Mountain Lion but are solved in Mavericks. I think they only applied to pop3 mail boxes and not imap accounts

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top