Skip to main content
wckdtall
Inspiring
September 4, 2025
Question

MAC - Read Image Dimensions without opening for any extension

  • September 4, 2025
  • 2 replies
  • 228 views

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.

2 replies

Stephen Marsh
Community Expert
Community Expert
September 4, 2025

And yet another option is ExifTool.

wckdtall
wckdtallAuthor
Inspiring
September 5, 2025

Love exiftool, wanted something that I didn't have to install in addition.

Legend
September 4, 2025

You could also just use Bridge.

_wckdTall_
Inspiring
September 4, 2025

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.

Legend
September 4, 2025

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.