• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update linked smart objects broken file path

Explorer ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

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?

TOPICS
Actions and scripting

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Nov 26, 2018 Nov 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.getT

...

Votes

Translate

Translate
Adobe
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Oops!...again mistake...Why there is no edit option in this forum? Let's correct my previous reply.

 

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

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

 

Now I have mentioned C:\\newfolder 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... 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Poorly understood. If you want to relink several layers at once, then you need to activate the required layer in turn and call the command (action) "placedLayerRelinkToFile" for each layer separately. Photoshop allows you to perform actions in scripts that you can reproduce manually.
Can you relink several layers at once with one action? I think no.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

If I have to call the script separately for each individual layer, then what is the benifit of the script? Instead I can select each individual layer, click the Relink option and select the file.... not a very big difference, right? 

Objective of a script is to automate the process.... isn't it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Still no luck!

 

script failed.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

The script does not need to be called multiple times. You need to call the "relink" command in the script as many times as you need.

 

In your example, the layer is locked from the top folder. You cannot, in this case, manually execute the "relink" command without unlocking the lock. You don’t deny that? So in the script, you must remove the lock. How to determine where to remove the lock is the second question.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

After unlocking the layer, it works! Thankyou... 

But for only one layer... I have hundreds of images (in master psb file, 96 layers). What I intend to do, I just would like to show the source folder to the script and the script will add this source folder path in front of each layer name (which is actually the respective image file name) and then rebuild the link and relink all the layers by this way at once. Is it possible by this script?

 

If not, would you please tell me how to execute the "relink" command from the script for multiple times?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

How does your "new_path" look like?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Oh I see! I forgot to rename the new_path = "C:\\A1"; in your code... I just copied your code and run ....... LOL, do you think that error for this reason? Ok, I will check it after correcting the path at tomorrow as the file is in my office and it is night time here!

 

I will let you know the result tomorrow... Thanks for identifying my fault!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Still no Luckscript failed.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Same question...

 

How does your "new_path" look like?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

I have corrected the path and it works! But for one selected layer only.... I need to iterate through all selected layers and change the link path to all selected layers at once. Please see my replies to previous post of @r-bin 

 

Please let me know if you help me in this respect by modifying the above existing code.

 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

A quick and dirty option would be to record the script into an action, then use another script to loop through the selected layers:

 

https://community.adobe.com/t5/photoshop/script-i-made-iterate-action-over-layers/m-p/8352874

 

or

 

https://raw.githubusercontent.com/Paul-Riggott/PS-Scripts/master/Run%20Action.jsx

 

You may wish to change the line from:

 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);

 

to

 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.30, 0.30, 0.30, 1]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

This code cycles through selected layers:

 

EDIT: Perhaps I'll find the right code next time!

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

Thankyou.... Please let me know while you find the right code.... you may try for loop for iterating the layers (I don't know javascript coding for Photoshop Script, but I know for loop coding for javascript and php). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

I do not understand what you want. You say you want to replace the linked file for 96 layers. Is it that you have 96 layers displaying one file? What's the point of this?
Why not make a copy of the Smart Object? Then by changing one of the objects, you will automatically change the others.

If you have 96 different layers and files, then the current script will not help you.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

No, I have 96 different images linked into 96 layers. That's why I am facing problem in relinking each image or layer to new location and that's why I want to get a script help in relinking the source folder automatically.

 

I think you now can understand what I want. Would you please help me in my case?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 11, 2020 Nov 11, 2020

Copy link to clipboard

Copied

What's the purpose of your script?
Why do you need to relink Smart Objects?
Do you want to replace with arbitrary files or just change the path of the files? Do I need to change the layer names while doing this? What is the structure of the file, is it necessary to examine all layers for relink (or relink only broken)?

In any case, this is a rather complex script.

And for its implementation, I need an accurate description of the process and your wishes.

Unfortunately, I do not have the time and desire for this.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 12, 2020 Nov 12, 2020

Copy link to clipboard

Copied

Thanks for your interest @r-bin . Suppose I have the following folder structures:

MyFolder

|

MyAnother Folder

|

ImageFolder (image1.jpg+image2.jpg) + image.psb

 

I have tried to show you the folder structure above.... You can see that image1.jpg and image2.jpg are placed as link in the image.psb. Now look at the structure below:

 

MyFolder

|

MyAnother Folder+ image.psb

|

ImageFolder (image1.jpg+image2.jpg) 

 

Now you can see that the psb file will be unable to detect image1.jpg and image2.jpg as their relative paths have been changed. It will now show broken link if the image.psb is opened from this location.

 

Now think instead of only 2 images (image1.jpg and image2.jpg), I have 96 images, all of them are from the ImageFolder. Now in case of the changed location of image.psb, I have to relink those 96 images one by one. This is very time consuming task.

 

Instead If you can make a script which will pop-up a window while run to select the source folder location of the images, then I can select ImageFolder (from the new location of the image.psb) and click Run.

 

Now the script will iterate automatically from layer to layer, will catch the previous relative path and replace it with current path for all the images.

 

I am not sure whether I am able to show you correctly or not... Let me know.

 

Thanks for all of your interest on my problem!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 26, 2020 Dec 26, 2020

Copy link to clipboard

Copied

@infomamun 

Perhaps my version is what you are looking for. Mine relinks everything which is selected. I use the layer filter methods to only show missing images in layer pallet, then select all and run script. If the files are there it relinks all of them automatically

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

LATEST

If all the linked files use the same link, if you update one than all the others should update automatically. Unless you linked them all in 1 by 1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 01, 2020 Dec 01, 2020

Copy link to clipboard

Copied

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

Catalina_RelinkError.PNG

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines