0

我正在使用拖放将电子邮件从 Mail 拉到共享服务器上的相关工作子文件夹中。然后我使用脚本按创建日期排序(这是我将它们拖过的日期),然后根据容器的名称重命名文件。

但是我想使用脚本从每个 .eml 文件中提取发送日期、发件人和主题,然后使用该信息重命名文件。

之前有一篇文章回答了类似的问题,但我不清楚(因为我是脚本新手)如何将它放入我的脚本中。它可以在:“AppleScript - 获取 .eml 文件的信息”中找到

答案是:

set fromField to text 7 thru -1 of (do shell script "cat /test.eml | grep From:")
set dateField to text 7 thru -1 of (do shell script "cat test.eml | grep Date:")
set toField to text 5 thru -1 of (do shell script "cat /test.eml | grep To:")
set subjectField to text 10 thru -1 of (do shell script "cat /test.eml | grep Subject:")

我想我需要有人编写实际的 shell 脚本并告诉我放置它的位置。

4

2 回答 2

0

尝试:

    set delim to " - "

set myFiles to (choose file with multiple selections allowed)
set TID to text item delimiters

repeat with aFile in myFiles
    set pFile to quoted form of (POSIX path of aFile)
    set {mDate, mFrom, mSubject} to every paragraph of (do shell script "cat " & pFile & " | grep -e Date -e From: -e Subject:")

    set mDate to trim(mDate, 7)
    set AppleScript's text item delimiters to " "
    set myDate to text item 3 of mDate & space & text item 2 of mDate & ", " & text item 4 of mDate
    set AppleScript's text item delimiters to {""}
    set myDate to (date myDate)
    set myDate to day of myDate & (month of myDate as integer) & year of myDate as text

    set mFrom to trim(mFrom, 7)
    set mSubject to trim(mSubject, 10)

    set newName to myDate & delim & mFrom & delim & mSubject

    -- You will have to edit newName so it meets file naming standards
    --tell application "System Events" to set aFile's name to mSubject
end repeat
set text item delimiters to TID

on trim(myText, firstChar)
    try
        set myText to text firstChar thru -1 of myText
    on error
        set myText to "None"
    end try
end trim
于 2012-12-19T13:41:20.400 回答
0

我会使用正则表达式,这将使您的脚本少于 10 行并且更易于阅读。

当然 AppleScript 本身不支持正则表达式,您只需在http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html安装 Satimage Osax 扩展

于 2015-05-15T20:10:38.980 回答