【问题标题】:AppleScript and Mail.app: checking if new messages contain a stringAppleScript 和 Mail.app:检查新消息是否包含字符串
【发布时间】:2012-06-05 02:17:36
【问题描述】:

我正在编写一个脚本来检查是否已提交特定的 Web 表单。

目前的脚本是这样写的:

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

任何帮助都将不胜感激。

干杯!

【问题讨论】:

    标签: email applescript


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      Applescript 有点棘手。您似乎正在尝试解析收件箱的 count,而不是实际的收件箱。

      试试这个脚本:

      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
      

      【讨论】:

        【解决方案3】:

        我实际上已经解决了这个问题,所以如果其他人需要帮助,我会在这里发布。检查它:

        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
        

        【讨论】:

        • 除非你在不到十分之一秒内收到所有邮件,否则你的脚本不会每次都正常工作,因为命令check for new mail不会等待,所以Mail还没来得及登录邮件服务器并检索任何待处理的邮件。
        【解决方案4】:

        补充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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-08-04
          • 1970-01-01
          • 1970-01-01
          • 2011-11-09
          • 2013-05-18
          • 2012-06-27
          • 2012-06-30
          相关资源
          最近更新 更多