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

MAC - Read Image Dimensions without opening for any extension

Enthusiast ,
Sep 04, 2025 Sep 04, 2025

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.

TOPICS
Actions and scripting , macOS
154
Translate
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
Adobe
Advocate ,
Sep 04, 2025 Sep 04, 2025

You could also just use Bridge.

Translate
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
Explorer ,
Sep 04, 2025 Sep 04, 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.

Translate
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
Advocate ,
Sep 04, 2025 Sep 04, 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.

Translate
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
Enthusiast ,
Sep 04, 2025 Sep 04, 2025

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.

Translate
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 Expert ,
Sep 04, 2025 Sep 04, 2025

And yet another option is ExifTool.

Translate
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
Enthusiast ,
Sep 04, 2025 Sep 04, 2025
LATEST

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

Translate
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