Skip to main content
Aureliu
Inspiring
November 26, 2018
Answered

Update linked smart objects broken file path

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

Active means visible? If so, Yes...they are visible.

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?

Legend
February 25, 2019

This code is perhaps more precise, but it doesn't change the link nonetheless...

var r1 = new ActionReference();

var d1 = new ActionDescriptor();

r1.putIndex(s2t('layer'), 1);

d1.putReference(s2t('target'), r1)

var d2 = new ActionDescriptor()

d2.putPath(s2t('link'), new File( "/path/to/whatever/new.jpg" ))

d1.putObject(s2t('to'), s2t('smartObject'), d2)

executeAction( s2t( "set" ), d1, DialogModes.NO );

And it doesn't return any error.

Davide


There still is the property "fileReference" which, logically, too, would need to be set.
But it also does not work.

I think all the properties of "smartObject" as well as "smartObjectMore" are read-only.

You can not change the property of the document "title" or "depth" for example.

)