Photoshop rename to layer name

故事扮演 提交于 2021-01-28 07:01:14

问题


I need a script to choose a folder, open the Photoshop files in the folder, then rename the files to the current name of layer plus the file extension. (Each of the layers will be named differently as the images have been created with a data merge. All I have so far is opening one image and getting the layer name, I can't figure out the repeat and the rename of the file:

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

回答1:


Like this :

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



回答2:


Brilliant that works a treat, just trying to backward engineer the script, in the photoshop function the repeat 5 times will that limit the script to only work with 5 files? and the variable tFile is that a constant as the variable doesn't seem to be declared? Still quite new to this so forgive my lack of knowledge and thanks again



来源:https://stackoverflow.com/questions/23316167/photoshop-rename-to-layer-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!