accepting certain types of files in prompt

ok, so I am trying to make a little script that prompt you for a file name and puts each file in a list. If the file is not an image of any type (see the property in my code) than an error message comes up saying that you can only choose images and then goes back to the first choosefile prompt. here is my pathetic code right now

property the_list : ""
property the_image : ""
property file_extensions : {".jpg", ".gif", ".tiff", ".png", ".pict", ".icns", ".pgm"}

set the_image to (choose file with prompt "Choose the image file that you want to delete.") as string
if the_image as string does not end with file_extensions then
	set errmess to (display dialog "You can only choose image files." buttons {"OK"} default button 1)
	return errmess
else
	set the_list to (choose from list the_image with prompt "Images to delete:") as string
	if the_list is "false" then error number -128 -- cancel
end if

Did you know that choose file has an option to set the allowed file types?

choose file‚v : Choose a file on a disk or server
choose file
[with prompt string] : the prompt to be displayed in the dialog box
[of type list of string] : a list of file types or type identifiers. Only files of the specified types will be selectable.
[default location alias] : the default file location
[invisibles boolean] : Show invisible files and folders? (default is true)
[multiple selections allowed boolean] : Allow multiple items to be selected? (default is false)
[showing package contents boolean] : Show the contents of packages? (Packages will be treated as folders. Default is false.)
→ alias : the chosen file

nice! thanks! i suppose that was in a dictionary that i should have checked:P

StandardAdditions

AHH! IT STILL WON’T WORK
this is my prompt

set the_image to (choose file of type ".jpg" with prompt "Choose the image file that you want to delete.") as string

Dominik didn’t say it explicitly, but but “type” in this case is referring to the older-style file type (file and creator), not a file extension.

Edit: Before you ask me how to get the file (and creator) type, you should know that they are often not used by applications anymore, and thus are probably not reliable for use in a distributed script.

er…I’m confused…could you just fix my prompt with the proper way so I can see what you mean?
EDIT: So is there anyway I could make this script workable?

sorry, I didn’t inted to confuse you …

maybe this could be a solution for you?

property file_extensions : {"jpg", "gif", "tiff", "png", "pict", "icns", "pgm"}
set workDir to choose folder with prompt "select folder"
tell application "Finder"
	set imgFiles to name of items of workDir whose name extension is in file_extensions
	set trashImgs to (choose from list imgFiles with prompt "Please choose files you want to trash" OK button name "Trash" with multiple selections allowed)
	delete (items of workDir whose name is in trashImgs)
end tell

While your aim isn’t quite clear to me, hendo, this might be closer to what your initial script was trying to do (bearing in mind that there are other types of image file whose extensions are not included in your list):

property file_extensions : {"jpg", "gif", "tiff", "png", "pict", "icns", "pgm"}

repeat
	set the_image to (choose file with prompt "Choose the image file that you want to delete:" without invisibles)
	if (info for the_image)'s name extension is in file_extensions then exit repeat
	display dialog "You can only choose image files."
end repeat

(* then do something with the_image *)

However, if possible, applying filtering to allow selection of only certain file types would be preferable. This example also allows multiple selections and returns a list:

set image_list to (choose file of type "public.image" with prompt "Choose the image files that you want to delete:" with multiple selections allowed without invisibles)

(* then do something with image_list *)