2014-04-16 19 views
-3

我正在爲我學校的皮卡系統編寫腳本。當我收到Gmail時,是否有辦法讓我的applescript觸發?我已經嘗試將它與IMAP連接到mail.app並制定觸發它的規則,但即使我收到電子郵件,我的郵件規則也不會觸發。有什麼建議麼?附:請不要在你的回答中使用任何編碼或蘋果字符巨型行話,我在這方面是一個業餘愛好者。Applescript to trigger on incoming Gmail

##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

這是關於郵件規則,而不是Applescript,並且很可能屬於[超級用戶](http://superuser.com/) –

+0

您有AppleScript郵件規則以及達裏克,這個問題是相當不錯的 –

+0

@djbazziewazzie如果很清楚這是OP所要求的規則,這可能是一個很好的問題。但是沒有上下文和一個特定的要求來避免「編碼或applescript巨無霸」。 –

回答

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-在山獅和更高的腳本需要被保存在〜/庫/應用程序腳本/ com.apple.mail文件夾來工作。

Mountain Lion中存在AppleScript郵件規則問題,但在小牛隊中解決。我認爲他們只適用於pop3郵箱而不是imap賬戶

+0

在代碼的第2行中,您提到了「mbox」和「message_list」。我知道他們是郵箱和郵件列表的佔位符,但什麼是郵件列表和郵箱?我是否必須在我的代碼中定義消息列表,或者規則是否爲我定義了它們?我只是想讓它通過收到我的Gmail帳戶的電子郵件運行。謝謝,user3473819 – user3473819

+0

我沒有發佈我的代碼,因爲我不認爲這是我的代碼中的一個小故障,我認爲這是一個郵件故障。我發佈了Stack Overflow,因爲我認爲可能有其他方法來觸發我的腳本。 – user3473819

+0

第2行是要觸發的處理程序的開始。這是當郵件進來時從郵件中調用的事件,並將執行該塊中的代碼。通過這個問題,我明白你沒有在你的代碼中包含這個處理程序,這就是爲什麼它不起作用的原因。 –