Skip to main content
Aureliu
Inspiring
November 26, 2018
Answered

Update linked smart objects broken file path

  • November 26, 2018
  • 3 replies
  • 8469 views

Our main image folder has been renamed, now many linked smart objects have a wrong path, and when opening the psd, photoshop asks me to update the path.

I would like to run a script and change the path to the new one. Is this even possible?

What I have so far, I can read the file path from a linked smart object like this:

var ref = new ActionReference();

ref.putIdentifier(charIDToTypeID('Lyr '), oObj.id );

var desc = executeActionGet(ref);

var smObj = desc.getObjectValue(stringIDToTypeID('smartObject'));

var sLocalFilePath = smObj.getPath(stringIDToTypeID('link'));

But this will give me the path if the file is correctly linked only. For broken file links getPath(stringIDToTypeID('link') is not available.

Is there a way to read the file path, if the linked file has been moved?

And is it possible to update the path via script then?

This topic has been closed for replies.
Correct answer r-bin

Try for active layer.

var new_path = "C:\\A1"; // YOUR REAL NEW PATH

var r = new ActionReference();   

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var d = executeActionGet(r); 

if (d.hasKey(stringIDToTypeID("smartObject")))

    {

    d = d.getObjectValue(stringIDToTypeID("smartObject")); 

    if (d.hasKey(stringIDToTypeID("link")))

        {

        var type = d.getType(stringIDToTypeID("link"));

        var pth;

        switch(type)

            {

            case DescValueType.ALIASTYPE:

                pth = d.getPath(stringIDToTypeID("link"));

                break;

            case DescValueType.STRINGTYPE:

                pth = d.getString(stringIDToTypeID("link"));

                break;

            defualt:

                throw("\n\nHmmm!\n\n");

            }

        var file = new File(pth);

        if (!file.exists)

            {

            file = new File(new_path + "/" + file.name);

            var d = new ActionDescriptor();

            d.putPath(stringIDToTypeID("null"), file);

            executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);

            alert("Done!")

            }

        else

            alert("File already exists");

        }

    else

        {

        alert("No link");

        }

    }

else

    {   

    alert("No smartObject");

    }

3 replies

Participating Frequently
December 1, 2020

executeActionGet is not working on macOS Catalina + Photoshop 2020. Below error is shown

Is this a known issue?
Please suggest if there is any other solution to update linked file path

 

infomamun
Inspiring
November 8, 2020

Error 8800: General Photoshop error occured. This functionality may not be avalilable in this version of Photoshop.

- The command "Relink to File" is not currently available;

Line 59

-> executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);

 

I am using Photoshop CC 2017 2017.0.0 Release. Any update how to resolve the above issue?

Tom Winkelmann
Inspiring
November 8, 2020

How does your "new_path" look like?

Tom Winkelmann
Inspiring
November 10, 2020

Still no Luck


Same question...

 

How does your "new_path" look like?

Legend
November 26, 2018

var sLocalFilePath = smObj.getString(stringIDToTypeID('link')); 

Aureliu
AureliuAuthor
Inspiring
November 26, 2018

getString() works! Do you know how to update the path of the smart object?

r-binCorrect answer
Legend
November 26, 2018

Try for active layer.

var new_path = "C:\\A1"; // YOUR REAL NEW PATH

var r = new ActionReference();   

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var d = executeActionGet(r); 

if (d.hasKey(stringIDToTypeID("smartObject")))

    {

    d = d.getObjectValue(stringIDToTypeID("smartObject")); 

    if (d.hasKey(stringIDToTypeID("link")))

        {

        var type = d.getType(stringIDToTypeID("link"));

        var pth;

        switch(type)

            {

            case DescValueType.ALIASTYPE:

                pth = d.getPath(stringIDToTypeID("link"));

                break;

            case DescValueType.STRINGTYPE:

                pth = d.getString(stringIDToTypeID("link"));

                break;

            defualt:

                throw("\n\nHmmm!\n\n");

            }

        var file = new File(pth);

        if (!file.exists)

            {

            file = new File(new_path + "/" + file.name);

            var d = new ActionDescriptor();

            d.putPath(stringIDToTypeID("null"), file);

            executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);

            alert("Done!")

            }

        else

            alert("File already exists");

        }

    else

        {

        alert("No link");

        }

    }

else

    {   

    alert("No smartObject");

    }