Applescript提取主题行

时间:2015-07-30 15:52:13

标签: applescript outlook-2011

这里总计n00b,绝对不是程序员。会喜欢一些苹果的帮助。我基本上试图从收件箱下面的特定文件夹中的电子邮件中提取主题行。我需要它来拉出主题行,寻找一些数字(例如123456)并拉出最后4位数字。然后将其放入文本文件中。以下是我到目前为止所做的,但它不起作用。我根本没有得到任何输出。任何指导将不胜感激!

tell application "Microsoft Outlook"
    set theAccount to exchange account “my account"
    set topFolder to folder "Inbox"
    set subFolder to folder “Stuff"
    set theMessages to messages of subFolder
    set folderPath to ((path to home folder from user domain as string) & “emails")
    repeat with aMessage in theMessages
        my SetSubject(subject of aMessage)
    end repeat
end tell



on SetSubject(theSubject)
    tell application "Microsoft Outlook"
        try
            save theSubject in ((path to home folder from user domain as string) & “emails" & “numbers.txt" as string)
        end try
    end tell
end SetSubject
end

1 个答案:

答案 0 :(得分:0)

我不知道您过滤主题的标准是什么。

这是一个示例,将指定邮箱中邮件的所有主题的最后4个字符写入numbers.txtemails个文件夹中的文件home folder,每行一个主题

如果发生错误 - 例如主题中的字符数小于4 - 文件将被可靠关闭并且脚本将中止。

set numbersFile to (path to home folder as text) & "emails:numbers.txt"

tell application "Microsoft Outlook"
    set theSubjects to subject of messages of folder "Stuff" of folder "Inbox" of exchange account "my account"
end tell

try
    set fileDescriptor to open for access file numbersFile with write permission
    repeat with aSubject in theSubjects
        write (text -4 thru -1 of aSubject & return) to fileDescriptor starting at eof
    end repeat
    close access fileDescriptor
on error
    try
        close access file numbersFile
    end try
end try