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

Using a Script to Add a File Name to an Image.

New Here ,
Jan 08, 2020 Jan 08, 2020

How to put file Name in file top left corner in file Using a Script to Add a File Name to an Image.

let me explain anybody experts.

20.1K
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
Adobe
New Here ,
Jul 29, 2023 Jul 29, 2023

Here it is, just as you asked for it, and then some! It's the GOLDENGUN of Photoshop name scripts; it will surely blow all others out of the water. Variables allow complete customization, and comments are plentiful for ease of editing.

Overall, the script will automatically center the filename and maximize the text size based on the limits you set, until it clips. It will also attempt to resize outputs automatically if you clip horizontally, as long as you keep reasonable values. The script offers three output options: filename, filename.extension, and path name. Additionally, you can select your font of choice from the comments, apply custom offsets from "auto center," and choose colors based on RGB values. Feel free to edit the Scaling Factors and other variables to achieve the exact output you desire, and verbose output is available as well. The variable for fonts has been improved with helpful comments, and I've added horizontal variable offsets that scale accordingly.

A special thanks to JJMack for the original script and the powerful tool, ChatGPT. Hopefully this helps someone, if you find it useful, please give me a thumbs up! If anyone wants to suggest additional features or finds any bugs, please let me know, and I will fix/add them ASAP.

#target photoshop // this command only works in Photoshop CS2 and higher
app.bringToFront();

if (!documents.length) {
  alert('There are no documents open.', 'No Document');
} else {
  // Call the main function wrapped in Document.suspendHistory()
  app.activeDocument.suspendHistory("Script Name", "main()");
}

function main() {
  // Common default Photoshop fonts with abbreviations
  var fontList = [
    { number: "1", abbr: "ari", name: "ArialMT" }, { number: "2", abbr: "cal", name: "Calibri" },
    { number: "3", abbr: "cmb", name: "Cambria" }, { number: "4", abbr: "cdn", name: "Candara" },
    { number: "5", abbr: "con", name: "Consolas" }, { number: "6", abbr: "cor", name: "Corbel" },
    { number: "7", abbr: "cms", name: "ComicSansMS" }, { number: "8", abbr: "crn", name: "CourierNewPSMT" },
    { number: "9", abbr: "geo", name: "Georgia" }, { number: "10", abbr: "imp", name: "Impact" },
    { number: "11", abbr: "lcn", name: "LucidaConsole" }, { number: "12", abbr: "mss", name: "MicrosoftSansSerif" },
    { number: "13", abbr: "plt", name: "PalatinoLinotype" }, { number: "14", abbr: "seg", name: "SegoeUI" },
    { number: "15", abbr: "tah", name: "Tahoma" }, { number: "16", abbr: "myp", name: "Myriad Pro" },
    { number: "17", abbr: "tnr", name: "TimesNewRomanPSMT" },
    { number: "18", abbr: "trb", name: "TrebuchetMS" }, { number: "19", abbr: "ver", name: "Verdana" }
  ];

  // Set the desired font name here (e.g., "ArialMT", "Calibri", etc.)
  var selectedFontName = "TimesNewRomanPSMT";

  // User-defined variables
  var fontName = selectedFontName;
  var textColor = new SolidColor;
  textColor.rgb.red = 255;
  textColor.rgb.green = 255;
  textColor.rgb.blue = 255;
  var minFontSize = 10; // Minimum font size in pixels
  var baseScalingFactor = 2.0; // Base scaling factor (0.01 = 1%) .1 = May force truncation

  // Additional scaling factor (modify this value as needed)
  var additionalScalingFactor = 1.0; // (1.0 = 100%) Over 100% may force truncation

  // Set the vertical offset percentage (0.0 means centered vertically, 0.25 is 25% up, -0.25 is 25% down)
  var verticalOffsetPercentage = -0.80; // Default value: 0.0 (centered vertically)

  // Set the horizontal offset percentage (0.0 means centered horizontally, 0.25 is 25% left, -0.25 is 25% right)
  var horizontalOffsetPercentage = -.70; // Default value: 0.0 (centered horizontally)

  // Option 1: Full Path Name (Uncomment to use)
  //var fileNameWithoutExtension = decodeURI(app.activeDocument.fullName);

  // Option 2: File Name (Uncomment to use)
  var fileNameWithoutExtension = decodeURI-app.activeDocument.name.split(".")[0]);

  // Option 3: File Name with Extension (Uncomment to use)
  //var fileNameWithoutExtension = decodeURI(app.activeDocument.name);

  // Automatically adjust baseScalingFactor based on the document's resolution
  var resolutionScalingFactor = app.activeDocument.resolution / 72; // 72 PPI as the reference resolution
  baseScalingFactor = baseScalingFactor * resolutionScalingFactor;

  // If Option 1 (Full Path Name) is enabled, set the maximum baseScalingFactor to 0.05 (5%)
  if (fileNameWithoutExtension) {
    baseScalingFactor = Math.min(baseScalingFactor, 0.042);
  }

  // If Option 3 (File Name with Extension) is enabled, adjust the additionalScalingFactor based on the resolution
  if (fileNameWithoutExtension) {
    var minAdditionalScalingFactor = 1.5; // Minimum additional scaling factor (0.5 = 50%) to avoid excessively small text
    var maxAdditionalScalingFactor = 6.0; // Maximum additional scaling factor (2.0 = 200%) to control text enlargement
    var resolutionScalingFactor = app.activeDocument.resolution / 72; // 72 PPI as the reference resolution
    additionalScalingFactor = Math.max(minAdditionalScalingFactor, additionalScalingFactor * resolutionScalingFactor);
    additionalScalingFactor = Math.min(maxAdditionalScalingFactor, additionalScalingFactor);
  }

  // Rest of the code...
  var invertOffset = true; // Set to true to invert the offset effect

  // Invert the vertical offset if needed
  if (invertOffset) {
    verticalOffsetPercentage *= -1;
    horizontalOffsetPercentage *= -1;
  }

  var doc = app.activeDocument;
  var docWidth = doc.width.value;
  var docHeight = doc.height.value;
  var availableWidth = docWidth - Math.abs(docWidth * horizontalOffsetPercentage); // Calculate the available width for the text based on the horizontal offset percentage
  var centerPosX = docWidth / 2 + (docWidth / 2) * horizontalOffsetPercentage; // Apply the horizontal offset
  var centerPosY = docHeight / 2 + (docHeight / 2) * verticalOffsetPercentage; // Apply the vertical offset

  // Text properties
  var fontSize = Math.max(minFontSize, availableWidth * baseScalingFactor * additionalScalingFactor); // Scale the font size based on the available width, base scaling factor, and additional scaling factor

  // Get the file name without the extension
  var textContent = fileNameWithoutExtension;

  // Save the current ruler and type
  var strtRulerUnits = app.preferences.rulerUnits;
  var strtTypeUnits = app.preferences.typeUnits;
  app.preferences.rulerUnits = Units.PIXELS;
  app.preferences.typeUnits = TypeUnits.PIXELS;

  // Resize the image to a fixed resolution (72 PPI) temporarily for consistent results
  var testRes = 72;
  var currentRes = doc.resolution;
  if (currentRes != testRes) {
    doc.resizeImage(doc.width.value, doc.height.value, testRes);
  }

  // Create a new text layer
  var textLayer = doc.artLayers.add();
  textLayer.name = doc.name;
  textLayer.kind = LayerKind.TEXT;
  textLayer.textItem.color = textColor;
  textLayer.textItem.font = fontName;
  textLayer.textItem.size = fontSize;
  textLayer.textItem.position = [centerPosX, centerPosY]; // Center-align the text with the offsets

  // Set text layer options
  textLayer.textItem.justification = Justification.CENTER; // Center-align the text horizontally
  textLayer.textItem.antiAliasMethod = AntiAlias.SHARP;

  // Set the text content
  try {
    textLayer.textItem.contents = textContent;
  } catch (error) {
    textLayer.textItem.contents = activeDocument.name;
  }

  // Restore the original resolution and preferences
  if (currentRes != testRes) {
    doc.resizeImage(doc.width.value, doc.height.value, currentRes);
  }
  app.preferences.rulerUnits = strtRulerUnits;
  app.preferences.typeUnits = strtTypeUnits;

  // Commenting out the final output
  /*
  var outputString = "Script executed successfully!\n\n";
  outputString += "Selected Font: " + fontName + "\n";
  outputString += "Font Size: " + fontSize + " pixels\n";
  outputString += "Text Color: RGB(" + textColor.rgb.red + ", " + textColor.rgb.green + ", " + textColor.rgb.blue + ")\n";
  outputString += "Horizontal Offset Percentage: " + (horizontalOffsetPercentage * 100) + "%\n";
  outputString += "Vertical Offset Percentage: " + (verticalOffsetPercentage * 100) + "%\n";
  outputString += "Text Content: " + textContent + "\n";

  alert(outputString, "Script Output");
  */
}
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
New Here ,
Jul 29, 2023 Jul 29, 2023

Here it is, just as you asked for it, and then some! It's the GOLDENGUN of Photoshop name scripts; it will surely blow all others out of the water. Variables allow complete customization, and comments are plentiful for ease of editing.

Overall, the script will automatically center the filename and maximize the text size based on the limits you set, until it clips. It will also attempt to resize outputs automatically if you clip horizontally, as long as you keep reasonable values. The script offers three output options: filename, filename.extension, and path name. Additionally, you can select your font of choice from the comments, apply custom offsets from "auto center," and choose colors based on RGB values. Feel free to edit the Scaling Factors and other variables to achieve the exact output you desire, and verbose output is available as well. The variable for fonts has been improved with helpful comments, and I've added horizontal variable offsets that scale accordingly.

A special thanks to JJMack for the original script and the powerful tool, ChatGPT. Hopefully this helps someone, if you find it useful, please give me a thumbs up! If anyone wants to suggest additional features or finds any bugs, please let me know, and I will fix/add them ASAP.

#target photoshop // this command only works in Photoshop CS2 and higher
app.bringToFront();

if (!documents.length) {
  alert('There are no documents open.', 'No Document');
} else {
  // Call the main function wrapped in Document.suspendHistory()
  app.activeDocument.suspendHistory("Script Name", "main()");
}

function main() {
  // Common default Photoshop fonts with abbreviations
  var fontList = [
    { number: "1", abbr: "ari", name: "ArialMT" }, { number: "2", abbr: "cal", name: "Calibri" },
    { number: "3", abbr: "cmb", name: "Cambria" }, { number: "4", abbr: "cdn", name: "Candara" },
    { number: "5", abbr: "con", name: "Consolas" }, { number: "6", abbr: "cor", name: "Corbel" },
    { number: "7", abbr: "cms", name: "ComicSansMS" }, { number: "8", abbr: "crn", name: "CourierNewPSMT" },
    { number: "9", abbr: "geo", name: "Georgia" }, { number: "10", abbr: "imp", name: "Impact" },
    { number: "11", abbr: "lcn", name: "LucidaConsole" }, { number: "12", abbr: "mss", name: "MicrosoftSansSerif" },
    { number: "13", abbr: "plt", name: "PalatinoLinotype" }, { number: "14", abbr: "seg", name: "SegoeUI" },
    { number: "15", abbr: "tah", name: "Tahoma" }, { number: "16", abbr: "myp", name: "Myriad Pro" },
    { number: "17", abbr: "tnr", name: "TimesNewRomanPSMT" },
    { number: "18", abbr: "trb", name: "TrebuchetMS" }, { number: "19", abbr: "ver", name: "Verdana" }
  ];

  // Set the desired font name here (e.g., "ArialMT", "Calibri", etc.)
  var selectedFontName = "TimesNewRomanPSMT";

  // User-defined variables
  var fontName = selectedFontName;
  var textColor = new SolidColor;
  textColor.rgb.red = 255;
  textColor.rgb.green = 255;
  textColor.rgb.blue = 255;
  var minFontSize = 10; // Minimum font size in pixels
  var baseScalingFactor = 2.0; // Base scaling factor (0.01 = 1%) .1 = May force truncation

  // Additional scaling factor (modify this value as needed)
  var additionalScalingFactor = 1.0; // (1.0 = 100%) Over 100% may force truncation

  // Set the vertical offset percentage (0.0 means centered vertically, 0.25 is 25% up, -0.25 is 25% down)
  var verticalOffsetPercentage = 0.0; // Default value: 0.0 (centered vertically)

  // Set the horizontal offset percentage (0.0 means centered horizontally, 0.25 is 25% left, -0.25 is 25% right)
  var horizontalOffsetPercentage = 0.0; // Default value: 0.0 (centered horizontally)

  // Option 1: Full Path Name (Uncomment to use)
  //var fileNameWithoutExtension = decodeURI(app.activeDocument.fullName);

  // Option 2: File Name (Uncomment to use)
  var fileNameWithoutExtension = decodeURI(app.activeDocument.name.split(".")[0]);

  // Option 3: File Name with Extension (Uncomment to use)
  //var fileNameWithoutExtension = decodeURI(app.activeDocument.name);

  // Automatically adjust baseScalingFactor based on the document's resolution
  var resolutionScalingFactor = app.activeDocument.resolution / 72; // 72 PPI as the reference resolution
  baseScalingFactor = baseScalingFactor * resolutionScalingFactor;

  // If Option 1 (Full Path Name) is enabled, set the maximum baseScalingFactor to 0.05 (5%)
  if (fileNameWithoutExtension) {
    baseScalingFactor = Math.min(baseScalingFactor, 0.022);
  }

  // If Option 2 (File Name) or Option 3 (File Name with Extension) is enabled, adjust the additionalScalingFactor based on the resolution
  if (fileNameWithoutExtension) {
    var minAdditionalScalingFactor = 3.5; // Minimum additional scaling factor (0.5 = 50%) to avoid excessively small text
    var maxAdditionalScalingFactor = 6.0; // Maximum additional scaling factor (2.0 = 200%) to control text enlargement
    var resolutionScalingFactor = app.activeDocument.resolution / 72; // 72 PPI as the reference resolution
    additionalScalingFactor = Math.max(minAdditionalScalingFactor, additionalScalingFactor * resolutionScalingFactor);
    additionalScalingFactor = Math.min(maxAdditionalScalingFactor, additionalScalingFactor);
  }

  // Rest of the code...
  var invertOffset = true; // Set to true to invert the offset effect

  // Invert the vertical offset if needed
  if (invertOffset) {
    verticalOffsetPercentage *= -1;
    horizontalOffsetPercentage *= -1;
  }

  var doc = app.activeDocument;
  var docWidth = doc.width.value;
  var docHeight = doc.height.value;
  var availableWidth = docWidth - Math.abs(docWidth * horizontalOffsetPercentage); // Calculate the available width for the text based on the horizontal offset percentage
  var centerPosX = docWidth / 2 + (docWidth / 2) * horizontalOffsetPercentage; // Apply the horizontal offset
  var centerPosY = docHeight / 2 + (docHeight / 2) * verticalOffsetPercentage; // Apply the vertical offset

  // Text properties
  var fontSize = Math.max(minFontSize, availableWidth * baseScalingFactor * additionalScalingFactor); // Scale the font size based on the available width, base scaling factor, and additional scaling factor

  // Get the file name without the extension
  var textContent = fileNameWithoutExtension;

  // Save the current ruler and type
  var strtRulerUnits = app.preferences.rulerUnits;
  var strtTypeUnits = app.preferences.typeUnits;
  app.preferences.rulerUnits = Units.PIXELS;
  app.preferences.typeUnits = TypeUnits.PIXELS;

  // Resize the image to a fixed resolution (72 PPI) temporarily for consistent results
  var testRes = 72;
  var currentRes = doc.resolution;
  if (currentRes != testRes) {
    doc.resizeImage(doc.width.value, doc.height.value, testRes);
  }

  // Create a new text layer
  var textLayer = doc.artLayers.add();
  textLayer.name = doc.name;
  textLayer.kind = LayerKind.TEXT;
  textLayer.textItem.color = textColor;
  textLayer.textItem.font = fontName;
  textLayer.textItem.size = fontSize;
  textLayer.textItem.position = [centerPosX, centerPosY]; // Center-align the text with the offsets

  // Set text layer options
  textLayer.textItem.justification = Justification.CENTER; // Center-align the text horizontally
  textLayer.textItem.antiAliasMethod = AntiAlias.SHARP;

  // Set the text content
  try {
    textLayer.textItem.contents = textContent;
  } catch (error) {
    textLayer.textItem.contents = activeDocument.name;
  }

  // Restore the original resolution and preferences
  if (currentRes != testRes) {
    doc.resizeImage(doc.width.value, doc.height.value, currentRes);
  }
  app.preferences.rulerUnits = strtRulerUnits;
  app.preferences.typeUnits = strtTypeUnits;

  // Commenting out the final output for smooth operation
  /*
  var outputString = "Script executed successfully!\n\n";
  outputString += "Selected Font: " + fontName + "\n";
  outputString += "Font Size: " + fontSize + " pixels\n";
  outputString += "Text Color: RGB(" + textColor.rgb.red + ", " + textColor.rgb.green + ", " + textColor.rgb.blue + ")\n";
  outputString += "Horizontal Offset Percentage: " + (horizontalOffsetPercentage * 100) + "%\n";
  outputString += "Vertical Offset Percentage: " + (verticalOffsetPercentage * 100) + "%\n";
  outputString += "Text Content: " + textContent + "\n";

  alert(outputString, "Script Output");
  */
}

 

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
New Here ,
Feb 15, 2025 Feb 15, 2025

I'm new and know nothing about scripting or coding. This is exactly what I want to do - write the filename centered about 15% from the bottom margin. This way I can watch them on my screen saver and remember what I'm seeing.

 

I am obviously doing something wrong. I have copied, pasted, and tried each and every one of the scripts posted here. They all show something is happening in the History tab and one or more new layers show up, but I can see nothing in any of those layers, even when the rest are turned off. Yet, if I click on Type and enter text, it shows up and works normally.

 

I'm trying to work on the .psd files, because .jpgs revert back to Bridge as a raw file and end up getting converted to .psd anyway.

 

Is there some preference or switch I need to fix?

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 ,
Feb 15, 2025 Feb 15, 2025
quote

Is there some preference or switch I need to fix?


By Ken287629603pzl


It's not possible for me to comment on the issues that you have had.

 

Please attach a sample PSD with a text layer with the desired font, size, position etc.

 

P.S. It might be easier for you to use alternative software for this task, where the feature is built-in and readily accessible:

 

https://www.xnview.com/en/xnconvert/

 

This example uses metadata, however, the text can also be the filename or other variables.

Stephen_A_Marsh_0-1715909916672.pngexpand image

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
New Here ,
Feb 16, 2025 Feb 16, 2025

The file "BB - Fort DeRussy. . .psd" is a reduction from the original file to fit on the upload here. The Screenshot 1.psd is that open image BEFORE applying Sanders final script above showing no history and only the primary layer. The Screenshot 2.psd shows the same information with the resultant image after running that script. If you open up the "BB - Fort DeRussy. . .psd" it will have the added layers, but no visible text.

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 ,
Feb 16, 2025 Feb 16, 2025

@Ken287629603pzl 

 

I'll take a look, but that wasn't what I asked for.  I wanted a working example of the final result, not the faulty results.

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 ,
Feb 17, 2025 Feb 17, 2025

@Ken287629603pzl 

 

If you use the move tool with "show transform controls" activated, you will find the text half on/half off the upper left canvas in 1.3pt white text.

 

2025-02-17_22-41-13.jpgexpand image

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
New Here ,
Feb 17, 2025 Feb 17, 2025

Thank you so much.

 

I had tried so many of these scripts with the same hidden results that I was beginning to think my computer had developed a grudge against me. I knew there had to be some simple preference or switch I had missed.

 

Now I can start fine tuning it.

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 ,
Feb 17, 2025 Feb 17, 2025

Try specifying the type size and location directly in the script. Some of the examples posted above have this code. You can also run an action after the script to set the location if that's easier.

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 ,
Feb 17, 2025 Feb 17, 2025

@Ken287629603pzl 

 

You're welcome.

 

The script code has //comments with explanations which would be the first place to start.

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
New Here ,
Mar 09, 2025 Mar 09, 2025

I'm still having problems with this script. I can now see the filename, except it's the full path+filename+extension. Not only that, but I'm using it exactly copied and pasted.

 

ONLY ONE modification to change the font from TimesNewRomanPSMT to ArialMT and the script crashes with 

Error 25: Expected:;.

Line 7

-> Call the main function wrapped in Document.suspendHistory()

 

What's wrong?

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 ,
Mar 09, 2025 Mar 09, 2025

I have no idea which script you are using, there were multiples posted in this topic. Perhaps it's time to try a different script, there are many on the forum to be found via a search.

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
New Here ,
Mar 10, 2025 Mar 10, 2025

I think I agree with you. I've found four different scripts so far. The problem is I don't know enough to cut and splice pieces together to end up with what I want - White bolded and shadowed Tahoma or Arial file name only near the bottom and centered on the image. I would love to be able to bulk apply it, but even if I have to do it individually to set font size and position, I'd do it.

 

Is there a specific site that explains the Adobe coding used in scripts, so a novice could try to figure out how to do the above?

 

Thank you.

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 ,
Mar 10, 2025 Mar 10, 2025

I'll post some code later on... Or you could just use xnconvert as previously suggested.

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 ,
Mar 10, 2025 Mar 10, 2025

Rather than cut and paste scripts, you might record an action that sets styling the way you want. Run a script to create the title text and then the action. A script can run an action so the two work together.

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 Beginner ,
Mar 10, 2025 Mar 10, 2025
LATEST
 
 
1) Put this script in you script folder  ( below after these instructions )
2) open your file in photoshop and create an action using these steps:
        1- increase cavas size toward top by however much you want ( do this if you want it above your file to the top left, if not skip this step)
        2- run the script (Under: File _ scripts _find the scipt)
        3- select all
        4- align to top and to left
        5- stop recording
        5- if you wanted it moved over or down just add an offset to the action
 
Here is the Script:
// this script is a variation of the script addTimeStamp.js that is installed with PH7
 
if ( documents.length > 0 )
{
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
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 middle
myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
myTextRef.size = 20;
}
catch( e )
{
// An error occurred. Restore ruler units, then propagate the error back
// to the user
preferences.rulerUnits = originalRulerUnits;
        app.displayDialogs = originalDialogMode;
throw e;
}
 
// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
else
{
alert( "You must have a document open to add the filename!" );
}

 

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