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

Need help editing strings from document info

Community Beginner ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

I am trying to create a string based on info from the active doument that is then saved as tab delimited text for use in spreadsheets.

I am new to scripting but I have been able to get the info from Photoshop but now I need to process some of it.

Here is the info I want in the order I want: filename, file size ( either working size or actual), pixel width, pixel height, inches width, inches height, image resolution, color mode.

example: CoolPicture_LYRD.psd     5.3 mb     3810    3810    5     5     762     RGB

Here is the info I have gotten back:

CoolPicture_LYRD.psd3810 px3810 px5 px5 px762 DPIDocumentMode.RGB

I need to make these changes:

  1. add the document size
  2. trim the px form the strings OR convert the "px" in the inches string to "in"
  3. short numbers to 6 characters ( for a number like 5.33333333333333 px)
  4. trim theDocumentMode. from the color mode info

I have tried using substrings which gets an error about functions

I have tried toString( ) and setting the range but with no luck.

any help would be appreciated. Thanks for looking.

Here is my script so far

//get the info from document that I need for my excel sheet

var imageHeightPixels = activeDocument.height

var imageWidthPixels = activeDocument.width

var fileResolution = activeDocument.resolution

var imageMode = activeDocument.mode

// get size in inches from pixel based measurement

var imageHeightInches = imageHeightPixels / fileResolution

var imageWidthInches = imageWidthPixels  / fileResolution

var imageName = activeDocument.name.toString()

var imageDimensions = new File ("~/desktop/File Info Report.txt") 

app.preferences.rulerUnits = Units.PIXELS

imageDimensions.open('a'); 

imageDimensions.write(imageName + "\t" + imageHeightPixels + "\t" + imageWidthPixels + "\t" + imageWidthInches + "\t" + imageHeightInches + "\t" + fileResolution + " DPI" + "\t" + imageMode + "\n"); 

activeDocument.close(SaveOptions.DONOTSAVECHANGES) 

 

imageDimensions.close();

TOPICS
Actions and scripting

Views

530

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

Advocate , Sep 29, 2016 Sep 29, 2016

There you go buddy:

var doc = app.activeDocument;

var currentUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var fileName = doc.name;

var fileSize = (File(doc.fullName).length / (1024 * 1024)).toFixed(2);

var fileWidthPx   = doc.width.value;

var fileHeightPx = doc.height.value;

var fileResolution = doc.resolution;

var fileWidthInch = (fileWidthPx  / fileResolution).toFixed(6);

var fileHeigthInch = (fileHeightPx / fileResolution).toFixed(6);

var colorMode = doc.mode.toString()

...

Votes

Translate

Translate
Adobe
Advocate ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

There you go buddy:

var doc = app.activeDocument;

var currentUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var fileName = doc.name;

var fileSize = (File(doc.fullName).length / (1024 * 1024)).toFixed(2);

var fileWidthPx   = doc.width.value;

var fileHeightPx = doc.height.value;

var fileResolution = doc.resolution;

var fileWidthInch = (fileWidthPx  / fileResolution).toFixed(6);

var fileHeigthInch = (fileHeightPx / fileResolution).toFixed(6);

var colorMode = doc.mode.toString().split(".")[1];

app.preferences.rulerUnits = currentUnits;

var outputString = fileName + "\t" +

  fileSize + " mb\t" +

  fileWidthPx + "\t" +

  fileHeightPx + "\t" +

  fileWidthInch + "\t" +

  fileHeigthInch + "\t" +

  fileResolution + " DPI\t" +

  colorMode + "\n"; 

var logFile = new File ("~/desktop/File Info Report.txt");

  logFile.open('a');   

  logFile.write(outputString);

  logFile.close();

doc.close(SaveOptions.DONOTSAVECHANGES);

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 Beginner ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

I was hoping for advice but this will work! I am going to figure out what you did. Then  I will try to make it change the formula for determining the file size based on file name substring. I appreciate your help immensely!

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
Engaged ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

Hi DevilsChariot,

Use this formula for file size

var fileSize = (File(doc.fullName).length / (1000 * 1000)).toFixed(1);

-yajiv

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 Beginner ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

LATEST

Both equations work.

Yajiv's equation will give the file size as calculated on a mac, and i believe on linux based systems.

Tomas's equation gives Windows interpretation of MB and GB.

I made a variable each so thanks to both of you.

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