Skip to main content
Shulipa Bernad
Inspiring
May 23, 2019
Answered

Check the file type!

  • May 23, 2019
  • 4 replies
  • 2726 views

Hello everyone! Once I open a document, is there any way to check the file type such as: jpg, tiff, png ...?

Thank you!

Correct answer D Fosse

This was a very strange thread. Why not just look at the title bar? Or turn on visible extensions in the operating system, so you know before even opening the file?

4 replies

alexanderl16240166
Inspiring
August 25, 2025

Old thread, but replying as this was the top result on google for me, so may prove useful to others. SuperMerlin's script works perfectly but is extremely slow on a larger PSB (4-5s for me). Pulling just the format instead of the whole document descriptor sped it up quite a bit:

function getFileFormatFast () {
    var s2t = stringIDToTypeID, c2t = charIDToTypeID;
    try {
        var ref = new ActionReference();
        // Ask ONLY for the 'format' property of the target document
        ref.putProperty(s2t('property'), s2t('format'));
        ref.putEnumerated(c2t('Dcmn'), s2t('ordinal'), s2t('targetEnum'));

        var desc = executeActionGet(ref);
        return desc.hasKey(s2t('format')) ? desc.getString(s2t('format')) : 'Unsaved File';
    } catch (e) {
        return 'Unsaved File';
    }
}
D Fosse
Community Expert
D FosseCommunity ExpertCorrect answer
Community Expert
August 25, 2025

This was a very strange thread. Why not just look at the title bar? Or turn on visible extensions in the operating system, so you know before even opening the file?

alexanderl16240166
Inspiring
August 25, 2025

Because if I'm scripting something on dozens of files and want it to handle things separately depending on if it's a layered PSD already or not, I don't want to have to tell it every time!

Shulipa Bernad
Inspiring
May 24, 2019

Hi Kukurykus , sorry for the late reply, the SuperMerlin script works perfectly regardless of where the document originated. yet I am grateful for your help. Thank you.

Kukurykus
Legend
May 24, 2019

I ask, because when you use the code in the alert from my very first reply you're getting the same:

alert(activeDocument.name.match(/[^.]+$/)[0])

so regardless of its origin, or what else do you mean by that?

Shulipa Bernad
Inspiring
May 24, 2019

You really are right!

alert (activeDocument.name.match (/ [^.] + $ /) [0])

I confess I did not understand, so I get a lot easier.

Both of these situations worked, to whom do I owe the correct answer credits?

Shulipa Bernad
Inspiring
May 23, 2019

Great job SuperMerlin! That's what I'm looking for. Thank you.

Kukurykus thanks for listening.

Kukurykus
Legend
May 23, 2019

Doesn't my code do the same, that you wanted?

Kukurykus
Legend
May 23, 2019

activeDocument.name.split(/\./)[1]

or for many dots:

activeDocument.name.match(/[^.]+$/)[0]

Shulipa Bernad
Inspiring
May 23, 2019

It was not quite that! Just an alert type message stating something like this: "This document is a jpg or tiff or png extension file ..." just show me its original format

Kukurykus
Legend
May 23, 2019

Then after opening command why don't you put one of proposed line surrounded by appropraite text to alert() ?