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

How to copy the name of the folder and paste as text in Photoshop

Contributor ,
Nov 05, 2016 Nov 05, 2016

I have about 200 image files of various sizes separated by folders, each folder represents a different customer. I need a text layer in each image that matches the name of each folder. It would be like this:

• 1 Select Folder

• 2 Copy the folder name

• 3 Open the image

• 4 Paste into a text layer. "Adding text in the image"

I found this script, it's almost all I need: Only a change: Change the file name to the folder name. Thank you.

// add document name in text layer;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// getting the name;

var docName = myDocument.name;

//var basename = docName.match(/(.*)\.[^\.]+$/)[1];

//getting the location;

//var docPath = myDocument.path;

// make the layer;

var myLayerRef = myDocument.artLayers.add();

myLayerRef.kind = LayerKind.TEXT;

myLayerRef.name = "text";

var myTextRef = myLayerRef.textItem;

myTextRef.size = 12;

myTextRef.font = "Arial";

myTextRef.justification = Justification.RIGHT;

//Set text colour in RGB values

var newColor = new SolidColor();

newColor.rgb.red = 192;

newColor.rgb.green = 44;

newColor.rgb.blue = 44;

myTextRef.color = newColor;

// Set the position of the text - percentages from left first, then from top.

myTextRef.position = new Array( myDocument.width -670, myDocument.height -1640);

myLayerRef.blendMode = BlendMode.NORMAL;

myLayerRef.opacity = 100;

myTextRef.contents = docName;

app.preferences.rulerUnits = originalUnits;

};

//that’s it; thanks to xbytor;

TOPICS
Actions and scripting
2.3K
Translate
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

Participant , Nov 07, 2016 Nov 07, 2016

Try this on line #11

var docPath = decodeURI(myDocument.path.name);

Translate
Adobe
Advocate ,
Nov 05, 2016 Nov 05, 2016

Hi,

give this a try:

// add document name in text layer;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// getting the name;

var docName = myDocument.name;

//var basename = docName.match(/(.*)\.[^\.]+$/)[1];

//getting the location;

var docPath = myDocument.path;

// make the layer;

var myLayerRef = myDocument.artLayers.add();

myLayerRef.kind = LayerKind.TEXT;

myLayerRef.name = "text";

var myTextRef = myLayerRef.textItem;

myTextRef.size = 12;

myTextRef.font = "Arial";

myTextRef.justification = Justification.RIGHT;

//Set text colour in RGB values

var newColor = new SolidColor();

newColor.rgb.red = 192;

newColor.rgb.green = 44;

newColor.rgb.blue = 44;

myTextRef.color = newColor;

// Set the position of the text - percentages from left first, then from top.

myTextRef.position = new Array( myDocument.width -670, myDocument.height -1640);

myLayerRef.blendMode = BlendMode.NORMAL;

myLayerRef.opacity = 100;

myTextRef.contents = docPath.toString();

app.preferences.rulerUnits = originalUnits;

};

Davide Barranca

http://htmlpanelsbook.com

www.davidebarranca.com

Translate
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
Contributor ,
Nov 05, 2016 Nov 05, 2016

D.Barranca you're a genius !! Came out perfect ... What To make it even better, would have a way to shorten the path leaving only the last folder? Thank you.

amostra.jpg

Translate
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
Enthusiast ,
Nov 05, 2016 Nov 05, 2016

Try this

var path_parts = path.split('/')

var last_folder = path_parts[path_parts.length-1]

Two things you need if Windows gives you '\' instead of '/' and if path has a trailing '/' (in which case the last folder is path_parts.length-2

Translate
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
Participant ,
Nov 05, 2016 Nov 05, 2016

You can split the string/path by forward slashes ("/"). This will give you an array of words, and you can simply choose the last one.

var str = '/e/Ultilidades/Imagens/Amostra';

str = str.split('/');

str = str[str.length - 1];

Translate
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
Contributor ,
Nov 06, 2016 Nov 06, 2016

Matias.Kiviniemi and Javier roche, in which line I should add the code, I'm not conceguindo. Thank you for your help.

Translate
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 06, 2016 Nov 06, 2016

Hi

matias.kiviniemi​ and JavierAroche​ your code should work. But only one question:

Why not simple replace this line #11

var docPath = myDocument.path; 

with this

var docPath = myDocument.path.name;

Regards

pixxxel schubser

Translate
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
Participant ,
Nov 06, 2016 Nov 06, 2016

Ha! I didn't realize matias.kiviniemi​ and I replied the exact same thing

  1. vardocPath=myDocument.path.name;

Yes, this is a cleaner solution since the document object already includes the path.name property. The solution matias and I gave is an alternative for when you have to parse a string.

Matias.Kiviniemi and Javier roche, in which line I should add the code, I'm not conceguindo. Thank you for your help.

Like pixxxel schubser said, this would replace line #11

Translate
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
Contributor ,
Nov 06, 2016 Nov 06, 2016

How to eliminate this "20%" in the name of the folder? Unfortunately this has muddled. Maybe subistituindo by "_". Example: Used_Images. Thank you..

imgs-(1).jpg

Translate
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
Participant ,
Nov 07, 2016 Nov 07, 2016

Try this on line #11

var docPath = decodeURI(myDocument.path.name);

Translate
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
Contributor ,
Nov 07, 2016 Nov 07, 2016
LATEST

It worked perfectly well! Thanks again JavierAroche.

Translate
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