Script Issue

CN
Posted By
chad_n_walker
Dec 14, 2006
Views
694
Replies
12
Status
Closed
I have a script that adds the file’s name to my document. What is the code (in the script) to adjust the size and font of the file name’s text? Also, is there a way to automate scripts. I tried incorporating it into an action with no success.

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

GD
george_dingwall
Dec 14, 2006
Hi Chad,

The font size and name will be contained in variables which are then used by the script to create the text. Without seeing your script it is impossible to guess at what the author might have used when the script was created.

In the script I use for doing this, the font name variable is ;

var textFont = "Arial-Black"

and the font size variable is ;

var textSize = 7 // Textsize = (% of short side of image)

What these might be in your script is anybody’s guess.

Bye for now.
CN
chad_n_walker
Dec 14, 2006
This script I am using is a variation of the script addTimeStamp.js that is installed with PH7

It doesn’t appear that they have set the font or size. Below is the script I am using. Thanks for the words of wisdom so far, any additional info would be greatly appreciated.

Thanks,
Chad

—–

if ( documents.length > 0 )
{
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

try
{
var docRef = activeDocument;

// Now create a text layer at the front
var myLayerRef = docRef.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = "Filename";

var myTextRef = myLayerRef.textItem;

// strip the extension off
var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "." ); if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length–;
}
fileNameNoExtension = fileNameNoExtension.join(".");

myTextRef.contents = fileNameNoExtension;

// off set the text to be in the bottom right corner
myTextRef.position = new Array( 969, 684 );
}
catch( e )
{
// An error occurred. Restore ruler units, then propagate the error back // to the user
preferences.rulerUnits = originalRulerUnits;
throw e;
}

// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
}
else
{
alert( "You must have a document open to add the filename!" ); }
CN
chad_n_walker
Dec 14, 2006
The text size and font are now A okay. The script is running great, just how I need it. However, you don’t happen to know how I can manipulate the script so it runs on all my open files? That would be amazing.
GD
george_dingwall
Dec 15, 2006
Hi Chad,

As there doesn’t appear to be font and size variables, I assume that the script is using what ever values are currently set in the character pallet. The problem with the script using the current settings is, if you have changed them since you last ran the script, it will now use the changed values rather than the values you had previously wanted.

The script I use allows you to choose some of the parameters yourself. Here is a link to my script. To use it in PS7, you will need to rename it so that the extension is changed from .jsx to .js

<http://www.georgedingwall.co.uk/downloads/Filename.jsx>

To run the script on multiple files, all you need to do is record an action whlie you run the script on an image. When you have the action, you then use the File/Automate/Batch option and then run the action on all of your open files. You can also run the action on a folder of images without opening them first.

Hope this helps.
CN
chad_n_walker
Dec 15, 2006
Your script works great. I only have one question. If I am using a font like Courier, how do I make it bold. I tried hacking around and adding a:

var textStyle = bold

It did not work.

thanks for everything so far. A real life saver.
DM
dave_milbut
Dec 15, 2006
you can set a "TextItem" object (or use george’s "myTextRef" var) and set the "FauxBold" attribute = true, or you can use an actual bold font.

i.e.

var textFont = "Arial-Black"

should read something like:

var textFont = "Arial-Black-Bold" (or whatever the scripting equivilent is)
CN
chad_n_walker
Dec 15, 2006
Still fuzzy on what the code would look like if I use George’s myTextRef var. I am seeing where I would put it (under myTextRef.font, etc. But how would it look, I tried this:

myTextRef.Style = "FauxBold"

But it didn’t work. I am still getting used to scripting so please be patient.

thanks
GD
george_dingwall
Dec 15, 2006
Hi Chad,

The font I used in the script is Arial-Black. As far as I know, this font does not have a Bold option. It is already a very bold version of Arial.

To use any font in a script, you have to know the Postscript Name for the font. The filename of the font wont do.

I use a script to find out this name for any font I want to use in a script. Remember however, if your script is going to be used on more than one computer, you would need to have the exact same font on every computer that would be running the script. That’s why I use Arial-Bold, it’s one of the scripts that’s on just about every computer in the world. For the version of this script that I use on my own computer I use a more ornate font, which might not be available on other computers.

Here’s the script I use to ID a font for use in a script. I don’t remember where I got this script from, but it was probably either Xbytor or Larry Ligon over on the scripting forum.

– – – – script begins here

// use this script to determine the Postscript name of a font

if (documents.length > 0) {
docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
if (layerRef.kind == LayerKind.TEXT){
alert(layerRef.textItem.font);
}
}

– – – – script ends here

To use the script just type some text using the font you have chosen and then run the script. You will get a small alert box up with the Postscript name of the font displayed. You need to use the exact form and spelling of whatever is displayed in the script. So if you wanted to use Arial Bold, running the script will tell you that the Postscript name is Arial-BoldMT. You would then simply replace what is currently in the script with that.

Hope this helps.
DM
dave_milbut
Dec 15, 2006
there you go! good on ya george! 🙂

myTextRef.Style = "FauxBold"

no, to use fauxbold, it looks like you’d use

myTextRef.FauxBold=true;
CN
chad_n_walker
Dec 15, 2006
All up and working now. Thanks for all the great advice everyone. Truly appreciate it.
DM
dave_milbut
Dec 16, 2006
don’t thank me (you’re welcome! <g>) i just had a slow afternoon and was up for some googling and reading api docs. george is the hero here for sharing his scripts! good work man!

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

Related Discussion Topics

Nice and short text about related topics in discussion sections