Choose every image

I try to choose every image in folder. I could use “every item whose file type is in {“jpg”, “gif”, “png”, “tif”, “tiff”}”, but there must be easier way than list all image file types.

You need to provide much more detail regarding what you’re doing before your question can be answered by anyone here.

I try to get list of files in desktop, which are images (jpg, gif…).

Isnt there something like: every item in (path to desktop) whose kind is picture?

What do you need to do with the information? (There are several ways to accomplish the task, and knowing the goal will help people suggest techniques.)

When i have that list, i will move all these files to another folder.

You can use Spotlight data to get the POSIX path to every image file in a specified folder:


set searchFolder to quoted form of POSIX path of (choose folder)
set AllPics to paragraphs of (do shell script "mdfind -onlyin " & searchFolder & " 'kMDItemContentTypeTree == public.image'")
-- to get HFS form:
repeat with aFile in AllPics
	set contents of aFile to POSIX file aFile
end repeat

For some reason, that code fails. It takes for ever to do that second row.

I tried folder actions too, but it fails too:

on adding folder items to this_folder after receiving these_items
	tell application "Finder" to set file_list to every item in folder "Macintosh HD:Users:cirno:Desktop:" whose file type is in {"jpg", "gif", "png", "tif", "tiff"}
	tell application "Finder" to move every item in file_list to folder "Macintosh HD:Users:cirno:Desktop:test:"
end adding folder items to

Hi cirno,

the problem is file type: the file type is not specified unconditionally,
it would be better to retrieve the file extension like this:

tell application "Finder"
	set file_list to every document file of folder (desktop as string) whose name extension is in {"jpg", "gif", "png", "tif", "tiff"}
	move file_list to folder ((desktop as string) & "test:")
end tell

The most likely reasons for its failure are these:

  1. You don’t have Spotlight enabled on the folder holding the pictures
  2. You aren’t running OS X Tiger
  3. Spotlight is language dependent (I don’t know if this is true), so the search condition is different in your language.

On my machine the script above (I’ve added “as alias”) finds over 1000 images in nested folders and converts them to HFS aliases in 3.22 seconds.

If you run this (choosing virtually any image of interest), it will tell you all the attributes you can search for.

set P to paragraphs of (do shell script "mdls " & quoted form of POSIX path of (choose file))