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:
|
I need to make these changes:
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();
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()
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);
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!
Copy link to clipboard
Copied
Hi DevilsChariot,
Use this formula for file size
var fileSize = (File(doc.fullName).length / (1000 * 1000)).toFixed(1);
-yajiv
Copy link to clipboard
Copied
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.