Copy link to clipboard
Copied
Hi,
I've searched for a solution like this around the forums, and while a lot of variations exist on this idea, I've not found one that does exactly this as yet, perhaps you could help?
So, I've got a handful of PSD files, let's say they're called
- poster.psd
- cover.psd
- advert.psd
In each of these files exists the same text, let's say it's social media info, for this example we'll say
- twitterusername
- instagramusername
Is there a way, via one script, to change the social media info across those 3 PSD files, without me running the script one each PSD, one at a time? Perhaps if I simply have them all open, it checks them each and replaces text?
Many thanks in advance. If anyone can provide a solution it'd be a huge time saver, and I'd be more than willing to pay/donate some money for the effort.
Edit: Sorry, I'm using Adobe Photoshop CC v19.4.1
You can open the files from within the script and there are multiple ways to specify the files:
1) If it is always the same files, you could hard code the paths to each into the script (this is the easiest, but not very flexible)
2) You could have the script call app.openDialog() which will bring up a file selection window where the user can select all of the relevant files
How you go about finding and replacing the text will differ based on how you have structured the .psd files (for exampl
...Copy link to clipboard
Copied
You can open the files from within the script and there are multiple ways to specify the files:
1) If it is always the same files, you could hard code the paths to each into the script (this is the easiest, but not very flexible)
2) You could have the script call app.openDialog() which will bring up a file selection window where the user can select all of the relevant files
How you go about finding and replacing the text will differ based on how you have structured the .psd files (for example, is the text in its own layer?). Also if you make the structure and naming conventions (for layer names, etc...) the same across the documents it will make scripting the solution much easier.
If you posted an example or two of your files, I can help.
I created the minimal example below:
and wrote the following script which (I think) accomplishes your goal:
#target photoshop
var files = app.openDialog("Please select the relevant files");
var newTwitter = prompt("Type the new Twitter handle:");
var newInstagram = prompt("Type the new Instagram handle:");
for(var i = 0; i < files.length; i++) {
var file = new File(files[i]);
var docRef = app.open(file);
var twitterLayer = docRef.artLayers.getByName("twitterHandle");
twitterLayer.textItem.contents = newTwitter;
var instagramLayer = docRef.artLayers.getByName("instagramHandle");
instagramLayer.textItem.contents = newInstagram;
docRef.close(SaveOptions.SAVECHANGES)
}
Let me know if this makes sense of if you have additional questions!
Copy link to clipboard
Copied
Wow, that's awesome! I've been using Photoshop for half my life and didn't even know you could do this kinda thing.
Can I pay you for your time on this?
In fact, sorry, just one thing I'm realising - is it possible to target text inside a group, as well as outside? This would really be quite useful. Let's call the groups "twitterWrapper" and "instagramWrapper" for consistencies sake.
Copy link to clipboard
Copied
Do you mean the text layers containing the usernames are in layer groups like this?
To handle this you will first need to use the layerSets object before getting the specific layers. See below:
#target photoshop
var files = app.openDialog("Please select the relevant files");
var newTwitter = prompt("Type the new Twitter handle:");
var newInstagram = prompt("Type the new Instagram handle:");
for(var i = 0; i < files.length; i++) {
var file = new File(files[i]);
var docRef = app.open(file);
var twitterGroup = docRef.layerSets.getByName("twitterWrapper");
var twitterLayer = twitterGroup.artLayers.getByName("twitterHandle");
twitterLayer.textItem.contents = newTwitter;
var instagramGroup = docRef.layerSets.getByName("instagramWrapper");
var instagramLayer = instagramGroup.artLayers.getByName("instagramHandle");
instagramLayer.textItem.contents = newInstagram;
docRef.close(SaveOptions.SAVECHANGES)
}
No need to pay me. Pay it forward somehow 🙂
Copy link to clipboard
Copied
Wow, truly fantastic help. You've saved my workflow a lot of time, thank you!
Copy link to clipboard
Copied
I have been able to use this script for a single file but I get this error when trying to open multiple files:
Error 1233: Expected a reference to an existing File/Folder
Line: 11 -> var docRef = app.open(file);
Any guidance would be much appreciated.
Doug
CC Photoshop 22.5.1
Copy link to clipboard
Copied
I corrected the codes. Try again...
Copy link to clipboard
Copied
Thank you!
How would I target subfolders within a psd file with multiple art boards:
Copy link to clipboard
Copied
activeDocument
.layerSets.getByName('Artboard 1')
.layerSets.getByName('Folder')
.artLayers.getByName('Text file')
Copy link to clipboard
Copied
Thank you. I think I didn't ask the right question. I don't always know what the artboard name is. Is there a way to modify this code to include "generic" artboards where I don't know the artboard names or number?
Copy link to clipboard
Copied
lS = [].slice.call(activeDocument.layerSets)
while(lS.length) alert(lS.shift().name)
Copy link to clipboard
Copied
Thank you Kukurykus for your help.
Again, I don't think I asked the right question. How would the code below be modified so that before looking at layer sets, it would look for parent artboards that have random names. The psd files also don't have the same number of artboards. The code below gets an error because it looks for a folder then the text layer. I am looking for a script that can search a random number of artboards and for each artboard then looks for a folder and the text layer.
Does that make sense?
#target photoshop
var files = app.openDialog("Please select the relevant files");
var newTwitter = prompt("Type the new Twitter handle:");
var newInstagram = prompt("Type the new Instagram handle:");
for(var i = 0; i < files.length; i++) {
var file = new File(files[i]);
var docRef = app.open(file);
var twitterGroup = docRef.layerSets.getByName("twitterWrapper");
var twitterLayer = twitterGroup.artLayers.getByName("twitterHandle");
twitterLayer.textItem.contents = newTwitter;
var instagramGroup = docRef.layerSets.getByName("instagramWrapper");
var instagramLayer = instagramGroup.artLayers.getByName("instagramHandle");
instagramLayer.textItem.contents = newInstagram;
docRef.close(SaveOptions.SAVECHANGES)
}
Copy link to clipboard
Copied
If it's like in your example a one layer set (contained in distinct artboard) with one layer, check kind of each to be sure that's text layer you are looking for:
lS = [].slice.call(activeDocument.layerSets), txt = 'LayerKind.TEXT'
while(lS.length)alert(lS.shift().layerSets[0].artLayers[0].kind==txt)
Copy link to clipboard
Copied
hi , thanks for your grate support
could you tell me
var files = app.openDialog("Please select the relevant files"); var newTwitter = prompt("Type the new Twitter handle:"); var newInstagram = prompt("Type the new Instagram handle:");
, can we set the CSV as auto opening and detect relevant Collom for Twitter and other Collom for inta save auto (already save it)
I want set detect data from CSV without manually entering
can we do it