【问题标题】:Search Mailbox of Mail.app with Applescript使用 Applescript 搜索 Mail.app 的邮箱
【发布时间】:2013-01-26 22:18:43
【问题描述】:

我希望能够在苹果的 mail.app 中的邮箱中搜索一个阶段或单词,然后以某种方式返回或复制从搜索结果中成功返回的电子邮件已发送的所有电子邮件地址来自..如果你明白我的意思

我认为这样做的唯一方法可能是 applescript,但如果其他人知道任何其他方法,请告诉我 :)

【问题讨论】:

    标签: search macos email applescript


    【解决方案1】:

    Mail.app 不允许直接通过 Applescript 进行搜索,但这可以解决问题,虽然它有点慢,因为它必须遍历每条消息:

    global searchTerm
    property emailList : {}
    
    set searchTerm to "aSearchTerm"
    
    tell application "Mail"
    
        set theInbox to inbox
    
        set firstMessage to 1
        set lastMessage to (get count of messages in theInbox)
    
        repeat with thisMessage from firstMessage to lastMessage
            set currentMessage to message thisMessage of theInbox
    
            set messageContent to content of currentMessage
    
            if messageContent contains searchTerm then
                set end of emailList to sender of currentMessage
            end if
    
        end repeat
    
    end tell
    
    return emailList
    

    【讨论】:

    • 这行得通,但它非常非常慢。手动从 10-15 个搜索词中获取电子邮件(使用 Mail.app 中的搜索)将比为一个搜索词获取此脚本的结果更快。我在 2.53 Ghz Macbook Pro 上的 Mac OS X 10.6.8 上用 1000 条消息在收件箱上对此进行了测试。
    • 花了一些时间来弄清楚如何设置theInbox,所以我发布了最终对我有用的版本:set theInbox to mailbox "INBOX" of account "myaccount"
    【解决方案2】:

    您也可以在界面中调用真正的搜索,然后收集物品

        [Applications launch:@"Mail"];
        [Keyboard command_alt_press:'f'];
        [Keyboard paste:term];
    
    
    +(void) command_alt_press:(char)c{
        [self runScript:[NSString stringWithFormat:@"tell application \"System Events\" to keystroke \"%c\" using command option down",c]];
    }
    

    您似乎有能力完成其余代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      • 2010-12-09
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多