Search code examples
sedapplescriptphotoshop-cs3

Removing "copy #"-text from layers in photoshop using applescript


I am able to replace the name of every layer of the current document, but when I pass it "where name ends with" it fails & the exception does not give any valuable feedback.

tell application "Adobe Photoshop CS3"
tell current document
    set name of every layer where name ends with "copy*" to "replace_using_sed"
end tell

end tell

Can you spot the error or perhaps you know an alternative way about this?


Solution

  • The copy* is causing the error. You can't use * as wildcard in AppleScript. Instead, use ... where name contains "copy" ....

    Here's my working version of your script (tested with Photoshop CS5):

    tell application "Adobe Photoshop CS3"
        set layerList to name of every layer in current document where name contains "copy"
    end tell
    
    repeat with currentName in layerList
        set layerName to text 1 thru ((offset of "copy" in currentName) - 1) of currentName
        tell application "Adobe Photoshop CS3"
            set (the name of first layer in current document where name contains "copy") to layerName
        end tell
    end repeat