Applescript 如何打开文本文件并使用文件中的文本重命名它?

Applescript 如何打开文本文件并使用文件中的文本重命名它?,applescript,Applescript,我正在尝试使用文件文本中的字符串用applescript重命名一些文本文件。这些文件都是旧的usenet消息,它们的名字都非常混乱,比如REARIY-1。我已经知道了如何读取文件并找到我想要的文本字符串(按主题:)我还知道了如果文本中有用户类型,如何重命名文件,但是我在打开文件读取文件以及获取允许重命名文件的路径时遇到了问题 到目前为止,我所做的最好的工作如下(这要求用户小心地选择同一个文件两次): 您只需将第三行更改为: set foo to choose file with multiple

我正在尝试使用文件文本中的字符串用applescript重命名一些文本文件。这些文件都是旧的usenet消息,它们的名字都非常混乱,比如REARIY-1。我已经知道了如何读取文件并找到我想要的文本字符串(按主题:)我还知道了如果文本中有用户类型,如何重命名文件,但是我在打开文件读取文件以及获取允许重命名文件的路径时遇到了问题

到目前为止,我所做的最好的工作如下(这要求用户小心地选择同一个文件两次):


您只需将第三行更改为:

set foo to choose file with multiple selections allowed
set fileAlias to foo as alias
set footext to read file ((choose file with prompt "phhhht") as string)


你可以试试这样的

    set fileList to choose file with multiple selections allowed

set targetText to "Subject:"
set targetTextCount to count of characters in targetText
set extractedProperty to ""

repeat with thisItem in fileList
    set footext to paragraphs of (read file (thisItem as string))

    repeat with this_item in footext
        if this_item contains targetText then

            set extractedProperty to characters from ((offset of targetText in this_item) + targetTextCount) to -1 of this_item as string

            --log extractedProperty
            tell application "Finder"
                set name of (thisItem as alias) to (extractedProperty & ".txt")
            end tell
            exit repeat
        end if
    end repeat
end repeat
set footext to read file (foo as string)
    set fileList to choose file with multiple selections allowed

set targetText to "Subject:"
set targetTextCount to count of characters in targetText
set extractedProperty to ""

repeat with thisItem in fileList
    set footext to paragraphs of (read file (thisItem as string))

    repeat with this_item in footext
        if this_item contains targetText then

            set extractedProperty to characters from ((offset of targetText in this_item) + targetTextCount) to -1 of this_item as string

            --log extractedProperty
            tell application "Finder"
                set name of (thisItem as alias) to (extractedProperty & ".txt")
            end tell
            exit repeat
        end if
    end repeat
end repeat