Skip to main content
Participant
July 22, 2020
Answered

How can I convert a layer to Smart Layer in Photoshop using AppleScript?

  • July 22, 2020
  • 2 replies
  • 573 views

I've searched the documentation, AppleScript dictionary as well as the Adobe forums here and can't find a way to convert a layer to a Smart Object. Is it possible?

    This topic has been closed for replies.
    Correct answer Stephen Marsh

    I haven't checked the AS scripting reference, however, both AS and JS DOM coding is limited. What the DOM doesn't cover, one can usually achieve using AM code (Action Manager).  The most accessible form of this is recorded by the ScriptingListener plug-in.

    AppleScript can call "inline" code or reference an external script file to perform tasks not directly covered in the AS DOM.

     

    The AM code to convert the active layer to an Embedded Smart Object:

     

    executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

     

    The AppleScript code:

     

    tell application "Adobe Photoshop 2024"
    	
    	set js to "executeAction(stringIDToTypeID(\"newPlacedLayer\"), undefined, DialogModes.NO);"
    	
    	do javascript js
    	
    end tell

     

    Notice how the " double-quotes in the original code have been escaped \" with a backslash as the JS code is contained within open/close double-quotes in the AS code.

     

    Another option rather than escaping the double-quotes, is to use single-quotes:

     

    tell application "Adobe Photoshop 2024"
    	
    	set js to "executeAction(stringIDToTypeID('newPlacedLayer'), undefined, DialogModes.NO);"
    	
    	do javascript js
    	
    end tell

     

    If you wanted to reference an external JSX file:

     

    tell application "Adobe Photoshop 2024"
    	activate
    	do javascript of file "~/Desktop/createSO.jsx"
    end tell

     

    or

     

    tell application "Adobe Photoshop 2024"
    	activate
    	do javascript (file "Users:username:Desktop:createSO.jsx")
    end tell

     

     

    2 replies

    Jeeeeerome
    Participant
    April 17, 2024

    Did you find a solution, I searched a lot and I can't find it either... 😉

    Stephen Marsh
    Community Expert
    Stephen MarshCommunity ExpertCorrect answer
    Community Expert
    April 17, 2024

    I haven't checked the AS scripting reference, however, both AS and JS DOM coding is limited. What the DOM doesn't cover, one can usually achieve using AM code (Action Manager).  The most accessible form of this is recorded by the ScriptingListener plug-in.

    AppleScript can call "inline" code or reference an external script file to perform tasks not directly covered in the AS DOM.

     

    The AM code to convert the active layer to an Embedded Smart Object:

     

    executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

     

    The AppleScript code:

     

    tell application "Adobe Photoshop 2024"
    	
    	set js to "executeAction(stringIDToTypeID(\"newPlacedLayer\"), undefined, DialogModes.NO);"
    	
    	do javascript js
    	
    end tell

     

    Notice how the " double-quotes in the original code have been escaped \" with a backslash as the JS code is contained within open/close double-quotes in the AS code.

     

    Another option rather than escaping the double-quotes, is to use single-quotes:

     

    tell application "Adobe Photoshop 2024"
    	
    	set js to "executeAction(stringIDToTypeID('newPlacedLayer'), undefined, DialogModes.NO);"
    	
    	do javascript js
    	
    end tell

     

    If you wanted to reference an external JSX file:

     

    tell application "Adobe Photoshop 2024"
    	activate
    	do javascript of file "~/Desktop/createSO.jsx"
    end tell

     

    or

     

    tell application "Adobe Photoshop 2024"
    	activate
    	do javascript (file "Users:username:Desktop:createSO.jsx")
    end tell

     

     

    Jeeeeerome
    Participant
    April 17, 2024

    Wooow you're a boss! 

    I've been trying to do this with Applescript for months and I can't find a solution. Even ChatGpt can't do it 😉 Congratulations on your code

    It works perfectly.

    It was the only thing I didn't know how to do with Applescript on Photoshop. I don't know about Script Listener but I'll look more carefully.
    Thank you very much Stephen!

    Community Expert
    July 22, 2020

    Are you trying to Automate this fucntion? If so ehy not use Actions?

     

    WM

    -------------------------------------------------------------------------JVK | Editor/Designer/Software Instructor. Pr, Ae, Ch, Ps, Ai, Id
    soybabyAuthor
    Participant
    July 22, 2020

    Yes actually I'm trying to automate a series of steps like resizing and saving where creating a smart object is part of it but without using actions