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?
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
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.
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Still no luck!
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.
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?
Copy link to clipboard
Copied
How does your "new_path" look like?
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!
Copy link to clipboard
Copied
Still no Luck
Copy link to clipboard
Copied
Same question...
How does your "new_path" look like?
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
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]);
Copy link to clipboard
Copied
This code cycles through selected layers:
EDIT: Perhaps I'll find the right code next time!
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).
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
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