Skip to main content
Aureliu
Inspiring
November 26, 2018
Answered

Update linked smart objects broken file path

  • November 26, 2018
  • 3 replies
  • 8467 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?

Legend
November 8, 2020

Is the required layer active?

infomamun
Inspiring
November 8, 2020

Then what will happen, suppose I have linked object from 3 separate folders/directories. Now if without selection, the script works, then it will replace all the linked object to one specific folder stated at new_path, no matter the layers are selected or not. Then all will be relinked to one path only... but if I have 3 paths, will it be right?


I think, due to my grammatical error, my last reply is confusing to me. Let me clear it:

Suppose, the Layer-1 is linked to C:\\myfolder1\template.psb, Layer-2 & Layer-3 are linked to C:\\hisfolder\template.psb, Layer-4 is linked to C:\\herfolder\template.psb.

 

Now I have mentioned C:\\newfolder\images in the script. If the script will relink all the layers irrespective of selected layer, then all Layer-1, Layer-2, Layer-3 and Layer-4 will be relinked to C:\\newfolder\images... but I actually want to relink only Layer1, Layer-2 and Layer-3.

 

Will it not be good to relink the layers which are only selected? By this system, I can decide which layers are to be relinked actually.

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");

    }