Делаем Applescript Photoshop Layer Renamer умнее - PullRequest
0 голосов
/ 07 февраля 2020

Я работаю над яблочным скриптом, который указывает на папку .psds, проверяет количество слоев в файле и затем переименовывает эти слои в зависимости от того, какие имена слоев применяются в настоящее время.

Сейчас он указывает на папку и может переименовывать слои по порядку, но на случай, если есть дополнительные слои или слои вышли из строя, я хочу переименовать слои, только если в них уже есть определенное слово.

например: если художественный слой содержит «1», установите имя «Слой 1»

Я немного позаимствовал из поста здесь .

Текущая ситуация открывает файлы в папке, проверяет номер слоя, переименовывает на основе количества слоев, переключает видимость, сохраняет и перемещается.

Я хочу добавить некоторые условия, которые запускают переименования слоев, исходя из имени файла, в котором он находится, и имен слоев в файле (см. Комментарии в коде)

set inputFolder to choose folder
activate application "Adobe Photoshop CC 2019"
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)
        set layerNameCount to count of layerName
        tell application id "com.adobe.Photoshop"
            tell current document
                --condition here that checks if the file name has a letter code "ABC"
                if layerNameCount > 3 then
                    set name of art layer 1 to "Word_1" -- ad condition that only renames layers that have the number "1"
                    set name of art layer 2 to "Word_2" -- ad condition that only renames layers that have the number "2"
                    set name of art layer 3 to "Word_3" -- ad condition that only renames layers that have the number "3"
                    set name of art layer 4 to "Word_4" -- ad condition that only renames layers that have the number "4"
                    set name of art layer 5 to "Word_5" -- ad condition that only renames layers that have the number "5"
                    set visible of layers to false
                    set visible of layer "Word_3" to true
                    close saving yes
                end if
                if layerNameCount = 3 then
                    make new art layer with properties {name:"Word_1"} -- ad condition that only adds this layer if no layers contain "word 1"
                    make new art layer with properties {name:"Word_2"} -- ad condition that only adds this layer if no layers contain "word 2"
                    set name of art layer 3 to "Word_3" -- ad condition that only renames layers that have the number "3"
                    set name of art layer 4 to "Word_4" -- ad condition that only renames layers that have the number "4"
                    set name of art layer 5 to "Word_5" -- ad condition that only renames layers that have the number "5"
                    set visible of layers to false 
                    set visible of layer "Word_3" to true
                    close saving yes
                end if
                --                  
                --condition here that checks if the file name has a letter code "DEF"
                set name of art layer 1 to "Word_1" -- ad condition that only renames layers that have the number "1"
                set name of art layer 2 to "Word_2" -- ad condition that only renames layers that have the number "2"
                set name of art layer 3 to "Word_3" -- ad condition that only renames layers that have the number "3"
                set visible of layers to false
                set visible of layer "Word_3" to true
                close saving yes
                --
            end tell
        end tell
    end repeat
end tell

on getLayerName(myDoc)
    tell application "Adobe Photoshop CC 2019"
        set display dialogs to never
        open alias myDoc
        repeat
            tell current document to if exists then
                set layerName to (name of layers) as list
                return layerName
            end if
            delay 1
        end repeat
    end tell
    return "" -- no document
end getLayerName

Любая помощь с благодарностью.

...