Get first image in folder

I’m new to AppleScript as of today, but I’ve hit a small problem that a Google search didn’t seem to answer.

I have a folder full of JPEGs and want to find the first one. In my AppleScript there’s the line:

set theName to (get first file of folder aFolder as alias)

This works fine when the folder only contains jpegs, but sometimes the folder also contains other non-JPEG files.

What’s the best way (or any way) of finding the first JPEG, rather than the first file of any kind, in a known folder?

Thanks in advance

Hi,

you could filter the file by its name extension


set theName to (get first file of folder aFolder whose name extension is in {"jpg", "jpeg"}) as alias