使用 AppleScript 打开 Photoshop 文件中的所有智能对象

Open All Smart Objects inside a Photoshop file using AppleScript

我正在处理的图片有很多智能对象层。由于没有正式的方法可以一次打开所有智能对象的内容,我正在考虑使用 AppleScript 和 JavaScript.

但是我遇到了一个问题,当我打开第一个智能对象时,Photoshop 的焦点移动到新打开的图片(已经打开的智能对象的内容)。所以焦点应该再次更改到原始文件(具有许多智能对象的文件)以便打开下一个智能对象。

这可能很简单,但我不是很有经验,在过去的几天里,我找不到在 Photoshop 环境中执行此操作的方法。

这是我的代码:

on run
    tell application "Adobe Photoshop CS6"
        activate
        set Doc_Ref to the current document
        set Doc_Name to name of Doc_Ref
        tell Doc_Ref
            set layerList to name of every layer in Doc_Ref whose kind is smart object layer
            repeat with currentName in layerList
                set current layer to layer currentName
                my Edit_Smart_Layer()
            end repeat
        end tell
    end tell
end run

on Edit_Smart_Layer()
    tell application "Adobe Photoshop CS6"
        do javascript "editSmartLayer(); function editSmartLayer() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); executeAction( sTID('placedLayerEditContents'), desc01, DialogModes.NO );};" show debugger on runtime error 
    end tell
end Edit_Smart_Layer

P.S。我认为代码还应该检查智能对象层是否可见。

解决方案是:

on run {input}
    try
        tell application "Adobe Photoshop CS6"
            activate
            
            set Doc_Ref to the current document
            tell Doc_Ref
                try
                    set layerList to name of every layer in Doc_Ref whose kind is smart object layer
                on error
                    display dialog "The active picture does not have Smart Object Layers !"
                    return input
                end try
                
                repeat with currentName in layerList
                    set current layer to layer currentName
                    my Edit_Smart_Layer()
                    tell application "Adobe Photoshop CS6"
                        set current document to Doc_Ref
                    end tell
                end repeat
                display dialog "Opened Smart Objects: " & length of layerList
            end tell
        end tell
    on error
        display dialog "Please run Photoshop and open a picture !"
        return input
    end try
end run


on Edit_Smart_Layer()
    
    tell application "Adobe Photoshop CS6"
        
        do javascript "editSmartLayer(); function editSmartLayer() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); executeAction( sTID('placedLayerEditContents'), desc01, DialogModes.NO );};" show debugger on runtime error
        
    end tell
    
end Edit_Smart_Layer