// workingWithStrings.jsx // Copyright 2007 // Written by Jeffrey Tranberry // Photoshop for Geeks Version 1.0 /* Description: This script demonstates how to work with strings. Also demonstates how to ask Photshop for the document name and current layer name as well as set variables to strings. Use with one of the birding photos or a new document named "IMG_0918.tif" */ // enable double clicking from the // Macintosh Finder or the Windows Explorer #target photoshop // Make Photoshop the frontmost application // in case we double clicked the file app.bringToFront(); /////////////////////////// // MAIN // /////////////////////////// // Have Photoshop display an alert box with a // simple string in it. alert("Hello, Photoshop World!"); // Have Photoshop display an alert box with a // formatted string in it alert("Hello, Photoshop World!\nWelcome to Photoshop For Geeks\n\nSeptember 6th, 2007"); // Have Photoshop display an alert box with a // formatted string in it, but this time on // multiple lines so it's readable alert("Hello, Photoshop World!\n" + "Welcome to Photoshop For Geeks\n\n" + "September 6th, 2007"); // Have Photoshop display the name and version the application alert(app.name + " " + app.version); // You must have a document open for the follow // commands to work. // Have Photoshop display an alert box that // displays the active document object in it. // Application object Pg. 51 alert(app.activeDocument); // Have Photoshop display an alert box that // displays the document name as a string // Document property Pg. 87 alert(app.activeDocument.name); // Have Photoshop display an alert box that // displays the active document name as a string // but slice off the last four characters alert(app.activeDocument.name.slice(0,-4)); // Have Photoshop display an alert box that // displays the active document name as a string // but slice off the last four characters // and the first four characters alert(app.activeDocument.name.slice(4,-4)); // Have Photoshop display an alert box that // displays the active layer object in it // Document object property Pg. 87 alert(app.activeDocument.activeLayer.name); // Have Photoshop display an alert box that // displays the active layer name as a string // artLayer property Pg. 57 alert(app.activeDocument.activeLayer.name); // Have Photoshop display an alert box that // displays the active document name as a string // but slice off the last four characters // and append or add the layer name to the end // of the string alert(app.activeDocument.name.slice(4,-4) + app.activeDocument.activeLayer.name); // Have Photoshop display an alert box that // displays the active document name as a string // but slice off the last four characters // and append or add the layer name to the end // of the string with an underscore added between // the two strings alert(app.activeDocument.name.slice(4,-4) + "_" + app.activeDocument.activeLayer.name); // Set up some variables var clientName = "BirdingWeekly" var authorName = "CMarble" var fileType = ".jpg" // Concatenate the variables with a subset of the document name alert(authorName + "_" + clientName + "_" + app.activeDocument.name.slice(4,-4) + fileType); // Use the method 'substr' to get a specified portion of the string // The first 4 represents the number of characters to move in from the left // The second 4 represents the number of characters to extract. // show the value of 'serialNumber' which is '0918' alert(app.activeDocument.name.substr(4,4));