2012-06-05 42 views
2

我正在編寫腳本以檢查是否提交了特定的Web表單。AppleScript和Mail.app:檢查新郵件是否包含字符串

劇本至今讀取正是如此:

tell application "Mail" 
check for new mail 
set newmail to get the unread count of inbox 
repeat with msg in newmail 
    if msg's subject contains "New newsletter built by" then 
     return msg's subject 
    end if 
end repeat 
end tell 

我在我的收件箱中的腳本一起工作了未讀電子郵件,但我仍然得到一個錯誤:

error "Mail got an error: Can’t make 1 into type specifier." number -1700 from 1 to specifier 

任何將不勝感激。

乾杯!

回答

1
tell application "Mail" 
    check for new mail 
    repeat until (background activity count) = 0 
     delay 0.5 --wait until all new messages are in the box 
    end repeat 
    try 
     return subject of (first message of inbox whose read status is false and subject contains "New newsletter built by ") 
    end try 
end tell 
1

Applescript有點棘手。它看起來像你試圖解析收件箱的計數,而不是實際的收件箱。

試試這個腳本:

tell application "Mail" 
    check for new mail 
    -- instead of getting the unread count of inbox 
    -- let's set an Applescript variable to every message of the inbox 
    set myInbox to every message of inbox 
    repeat with msg in myInbox 
     -- and look at only the ones that are unread 
     if read status of msg is false then 
      -- and if the subject of the unread message is what we want 
      if msg's subject contains "New newsletter built by" then 
       -- return it 
       return msg's subject 
      end if 
     end if 
    end repeat 
end tell 
-1

其實我已經解決了這個問題,所以我將它張貼在這裏應該別人需要幫助。檢查它:

tell application "Mail" 
check for new mail 

set checker to (messages of inbox whose read status is false) 
set neworder to number of items in checker 

if neworder > 0 then 
    repeat with i from 1 to number of items in checker 
     set msg to item i of checker 
     if msg's subject contains "New newsletter built by " then 
      return msg's subject 
     end if 
    end repeat 
end if 
end tell 
+0

除非您收到的所有消息在不到十分之一秒,你的腳本將不能正確每次工作,因爲'檢查新郵件'命令不會等待,所以** Mail **將不會有時間登錄到郵件服務器並檢索任何待處理的郵件。 – jackjr300

+0

解決方案在我的答案 – jackjr300

0

添加到什麼jackjr300說....

tell application "Mail" 
    set x to unread count of inbox 
    check for new mail 
    delay 3 
    set y to unread count of inbox 
    set z to y - x 
end tell 

if x = y then 
    say "There is nothing to report" 
end if 

if z = 1 then 
    say "You have one new message" 
end if 

if z = 2 then 
    say "You have two new messages" 
end if 

if z = 3 then 
    say "You have three new messages" 
end if 
if z = 4 then 
    say "You have four new messages" 
end if 
if z = 5 then 
    say "You have five new messages" 
end if 
if z = 6 then 
    say "You have six new messages" 
end if 
if z = 7 then 
    say "You have seven new messages" 
end if 
if z = 8 then 
    say "You have eight new messages" 
end if 

if z = 9 then 
    say "You have nine new messages" 
end if 
if z = 10 then 
    say "You have ten new messages" 
else 
    say "You have more than ten new messages" 
end if 
相關問題