开发者

Search Mailbox of Mail.app with Applescript

开发者 https://www.devze.com 2022-12-14 09:02 出处:网络
I want to be able to search a mailbox in 开发者_如何学Goapple\'s mail.app for a phase or word, then somehow return or copy all of the email addresses from which the emails which have successfully retu

I want to be able to search a mailbox in 开发者_如何学Goapple's mail.app for a phase or word, then somehow return or copy all of the email addresses from which the emails which have successfully returned from the result of the search have been sent from.. if you get what i mean

I thought that the only way to do this is probably applescript but if anyone else knows any other way please tell me :)


Mail.app doesn't allow searches directly via Applescript but this will do the trick, though it is a bit slow because it has to iterate through each message:

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


you could also invoke a real search in the interface and then collect the items

    [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]];
}

you seem competent enough to complete the rest of the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消