Need help editing strings from document info
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:
|
I need to make these changes:
- add the document size
- trim the px form the strings OR convert the "px" in the inches string to "in"
- short numbers to 6 characters ( for a number like 5.33333333333333 px)
- 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();