Applescript Photoshop重命名为图层名

Applescript Photoshop重命名为图层名,applescript,rename,photoshop,Applescript,Rename,Photoshop,我需要一个脚本来选择一个文件夹,打开文件夹中的Photoshop文件,然后将文件重命名为当前图层名称加上文件扩展名。(由于图像是通过数据合并创建的,因此每个层的名称都会有所不同。到目前为止,我所拥有的只是打开一个图像并获取层名称,我无法确定文件的重复和重命名: set inputFolder to choose folder tell application "Finder" set filesList to files in inputFolder set myDoc to i

我需要一个脚本来选择一个文件夹,打开文件夹中的Photoshop文件,然后将文件重命名为当前图层名称加上文件扩展名。(由于图像是通过数据合并创建的,因此每个层的名称都会有所不同。到目前为止,我所拥有的只是打开一个图像并获取层名称,我无法确定文件的重复和重命名:

set inputFolder to choose folder
tell application "Finder"
    set filesList to files in inputFolder
    set myDoc to item 1 of filesList as string
    tell application "Adobe Photoshop CC"
        set display dialogs to never
        open alias myDoc
    end tell
end tell
tell application "Adobe Photoshop CC"
    set layerName to name of current layer of current document as string
    -- close current document saving no
    return layerName as string
end tell
像这样:

set inputFolder to choose folder
activate application "Adobe Photoshop CC"
tell application "Finder"
    set filesList to document files in inputFolder
    repeat with tFile in filesList
        set nExtension to name extension of tFile
        set layerName to my getLayerName(tFile as string)
        if layerName is not "" then
            set newName to (layerName & "." & nExtension)
            if newName is not name of tFile then -- else the name is already the layer name
                set i to 1
                repeat while exists item newName in inputFolder -- if same name in the folder (maybe same layer name)
                    set newName to (layerName & i & "." & nExtension)
                    set i to i + 1
                end repeat
                set name of tFile to newName
            end if
        end if
    end repeat
end tell

on getLayerName(myDoc)
    tell application "Adobe Photoshop CC"
        set display dialogs to never
        open alias myDoc
        repeat 5 times
            tell current document to if exists then
                set layerName to (name of current layer) as string
                close saving no
                return layerName
            end if
            delay 1
        end repeat
    end tell
    return "" -- no document
end getLayerName

这是一个很好的处理方法,只是尝试对脚本进行反向工程,在photoshop函数中,重复5次会限制脚本只处理5个文件吗?变量tFile是一个常量,因为变量似乎没有声明? 还是很新鲜,所以请原谅我知识的缺乏,再次感谢