Photoshop Scripts: Editing Text on a Text Layer

Since I donโ€™t have enough time to learn all about the PS script, I was wondering if you can help me.

It is very simple. I want to have JS-Script that modifies the text of the top layer . For example: The text is "# 005", the script should add 1, so it says "# 006". After that, it should export (Save for the Internet and devices with transparency @ 1280x720) a file with the current number (006).

Here's the layers screen (omg it in German! 11): imageshack.us/photo/my-images/706/helpal.png

+8
javascript scripting text photoshop layer
source share
1 answer

EDIT for downvoters:

Please, to help the community and avoid misleading / incorrect information (if I did something in this case), which makes StackOverflow a better place, add a comment below indicating what makes you think the code or directions is worth it for downvoting. If there is something wrong or misleading, I will find out one more thing for which I will be grateful.

First you will need to create an action.

  • Save the following code with a .jsx extension.
  • Open one of these images.
  • Create a new action and click the record button under the panel if it is not already active.
  • Go to File > Scripts > Browse and select a script
  • Termination Record
  • Go to the folder where the file was created and delete this new file

Then you will need to automate all this. If there is no open document ,

  • Go to File > Automate > Batch
  • Select the required Install and Action names from the options
  • For "Source" select "Folder", then select the folder with your multi-level files by clicking the "Select ..." button
  • This may not be necessary (depending on your color settings), but you can choose the 3rd and 4th options: Suppress File Open Options Dialogs and Suppress Color Profile Warnings . Since you did not enable the file open action during recording, save the 1st option Override Action Open Commands unselected. Otherwise, it will not open a single file, but still try to run the script * number of your files. If necessary, select the 2nd option Include All Subfolders .
  • Click the OK button.

An additional point for those using CS6: Adobe Developer Connection indicates that ...

Adobe Photoshop CS6 does not install the Scripting folder. Please use the links below to install the Samples, Documentation, and Script plug-in.

 function getTextLayer(target) { // this basically loops all the layers to find the // upmost text layer with the content #nn... and returns it if (target == null) return false; var layers = target.layers, layerLen = layers.length; for (var i = 0; i < layerLen; i++) { var layer = layers[i], isLayerSet = layer.typename == 'LayerSet', isValid = layer.kind == LayerKind.TEXT && /^\s*#\d+\s*$/.test(layer.textItem.contents); // we're allowing spaces around the text just in case if (!isLayerSet && !isValid) continue; if (isLayerSet) { var found = getTextLayer(layer); if (found) return found; } else return layer; } return false; } var doc; try { doc = app.activeDocument; // the front document } catch(e) {} var txtLayer = getTextLayer(doc); // obviously, the text layer if found if (txtLayer) { var num = txtLayer.textItem.contents.match(/\d+/)[0], // find the numeric part len = num.length, // find the length of the numeric part num = (parseInt(num,10)+1).toString(); // add 1 to that number while (num.length < len) num = '0' + num; // and adjust length if necessary so that eg // 032 will not become 33 but it will become 033 txtLayer.textItem.contents = '#' + num; // update layer content var ext = '.png', dir = decodeURI(doc.path) + '/png24', // to use the same directory where the layered file exists // just keep it as decodeURI(doc.path) // I added a folder here, which actually does not exist // but it doesn't matter because I'm making it create it // below in case there no such directory. fileName = dir + '/' + num + ext, i = 0; if (!Folder(dir).exists) Folder(dir).create(); // create the directory if it doesn't exist while (File(fileName).exists) fileName = dir + '/' + num + '-' + (++i) + ext; // if file with that name exists, add -n to the end of the name var file = new File(fileName), opts = new ExportOptionsSaveForWeb(); with (opts) { format = SaveDocumentType.PNG; PNG8 = false; } doc.exportDocument(file, ExportType.SAVEFORWEB, opts); // save for web } if (doc) { doc.close(SaveOptions.DONOTSAVECHANGES); // close the original layered document without saving } doc = null; // remove reference 
+14
source share

All Articles