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

Stripping first 4 characters from an 8 character file name in a script?

New Here ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

I have a script to add the file number to the front of the image for proofing. I would like to remove the first 4 characters in the 8 character file name in the script.

I don't code so I'm looking for the lines of code to add to the script.

It would help reduce paperwork errors when we show portraits.

Thanks for any help,

Fjuds

// this script is a variation of the script addTimeStamp.js that is installed with PH7

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 center

  myTextRef.position = new Array( docRef.width / 3, docRef.height / 1.03 );

  myTextRef.size = 60;

  }

  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!" );

}

TOPICS
Actions and scripting

Views

277

Translate

Translate

Report

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

Community Expert , Oct 24, 2017 Oct 24, 2017

You can put this line after line 23:

var shortName = fileNameNoExtension.substr (4)

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

This doesn't look like JavaScript for Adobe Acrobat.

Votes

Translate

Translate

Report

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 ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

Sorry, First time trying a form and posted to the wrong group. Its a Photoshop script.

Votes

Translate

Translate

Report

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 ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

[Question moved to Photoshop Scripting]

Votes

Translate

Translate

Report

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 ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

LATEST

You can put this line after line 23:

var shortName = fileNameNoExtension.substr (4)

Votes

Translate

Translate

Report

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