我正在为我学校的录音系统编写剧本。有一种方法可以在我获得Gmail时触发我的AppleScript吗?我已尝试将其与IMAP连接到mail.app并制定触发它的规则,但即使我收到电子邮件,我的邮件规则也不会触发。有什么建议?附:请不要在你的答案中使用任何编码或者应用程序mumbo-jumbo lingo,我在这方面是个业余爱好者。
##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
答案 0 :(得分:0)
您是否在脚本中包含了邮件规则处理程序?共享代码或部分代码总是更好,这些代码或代码不能帮助您更好地理解问题。它现在就像“我的车无法启动”,我们必须猜测可能出现的问题。
但是有些部分对于正常工作非常重要:
1-您是否包含perform mail action with messages
处理程序?此处理程序(在本例中为事件)必须包含在脚本中,它是在脚本内部触发邮件规则的起始事件。当脚本设置为邮件规则操作时,它不会run
您的脚本。
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-在Mountain Lion及更高版本中,脚本需要保存在〜/ Library / Application Scripts / com.apple.mail文件夹中才能工作。
Mountain Lion中存在AppleScript邮件规则问题,但在Mavericks中已解决。我认为他们只适用于pop3邮箱而不是imap帐户