Restrict choose file to PNG type

I want to restrict the choose file available type to PNG only, so you can only choose a PNG file. I’ve already tried this:

set theimage to (choose file of type {“PNGf”} with prompt “Choose an image file”)

“PNGf” doesn’t seem to be the right one. I’ve tried “PNG”, “.png”, but none of them work.

It appears that .png files do not have an identifiable file type. Try this script:

set a to (info for (choose file))'s file type

For a .jpg file, it returns:

“JPEG”

while for a .png, it returns an empty string.

I did a little reading here, and it SEEMS that there may be a way to set up your machine to give the .png files a file type, but I did not have time to go into the nasty details.

Hope this helps a little. If you go to the AS Language Guide, and look up Commands Reference (on the left), you can scroll down to the link for choose file. It covers this in more detail.

I believe file type is dependent on the actual file. However, in Mac OS X 10.4 or later, you should be able to use Uniform Type Identifiers instead.

choose file of type {"public.png"} without invisibles

Bruce,

Thank you very much that worked perfectly. And thanks to Craig too.