Copy link to clipboard
Copied
I was looking for a surefire method to read image dimensions and information without opening them in Photoshop on mac, and came across app.system. Using the sips command, and writing a temp file to get the variables over to Photoshop ended up working better than trying to read metadata from files, as it varies by extension. Here's the solution I came up with:
function dateInt() {
var theDate = new Date();
return theDate.getTime();
}
function readTextFile(file) {
file = File(file);
file.open('r');
var str = file.read();
file.close();
return str;
}
var tgtImg = 'IMAGE_PATH/IMAGE_NAME.ext'; //Edit this line
var dateFile = "sipsInfo_" + dateInt() + ".txt";
var dateFilePath = $.getenv("TMPDIR") + dateFile;
var osascriptCommand = 'sips -1 -g pixelWidth -g pixelHeight "' + tgtImg + '" > ' + dateFilePath;
app.system(osascriptCommand);
var textDims = readTextFile(dateFilePath);
var sipW = Number(textDims.match(/pixelWidth\: ([0-9]+)/g)[0].split(": ")[1]);
var sipH = Number(textDims.match(/pixelHeight\: ([0-9]+)/g)[0].split(": ")[1]);
File(dateFilePath).remove();
alert("Dimensions:\nW:" + sipW + "\nH:" + sipH)
Tested with PSD, PSB, TIF,JPG, PNG, which are all read consistently by sips.
Copy link to clipboard
Copied
You could also just use Bridge.
Copy link to clipboard
Copied
Bridge Talk in photoshop? I'm doing additional image manipulation inside of photoshop, so I need to get the information off the unopened files, to compare them to one another for smart objects/links.
Copy link to clipboard
Copied
Bridgetalk is a way to communicate between Adobe apps. I was saying just look at the files in the Bridge app.
You can also Image Events in an Applescript, it is a front end for SIPS. Calling shell commands can be a PITA and since Photoshop has native Applescript support, that might be easier. You would also not have to worry about returning values with a text file.
Copy link to clipboard
Copied
Thanks! This script was pretty straightforward, though the osa portion is always tricky. I've got a lot built in javascript, and sips aside they can be run on windows, so I needed a solution that runs in line.
Copy link to clipboard
Copied
And yet another option is ExifTool.
Copy link to clipboard
Copied
Love exiftool, wanted something that I didn't have to install in addition.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now