How to sort file types

I’ve got this script to process some folders in Photoshop:

on open folderDropped
set folderPath to folderDropped as string
set folderDropped to list folder folderDropped without invisibles
repeat with thisFile in folderDropped
set thisFile to folderPath & thisFile as alias
tell application “Adobe Photoshop 7.0”
---- Here it processes the files
end tell
end repeat
end open

In my folders though, there are also some text files that I should “filter” out of the repeat process; how?
thx,
Guido

Hi, Guido. You may want something like this:

on open droppedItems -- the parameter for an 'open' handler is a list of aliases

  set validExtensions to {"jpg", "gif"} -- add whatever extensions are relevant
  
  -- Cycle through all the dropped items
  repeat with thisFolder in droppedItems
    -- Check that each item is in fact a folder
    tell application "Finder"
      set isFolder to (class of item (thisFolder as string) is folder)
    end tell
  
    if isFolder then
      -- Get aliases to all and any picture files in the folder
      -- ('as alias list' errors if there's only one item)
      tell application "Finder"
        try
          set theFiles to (every file of folderDropped whose name extension is in validExtensions) as alias list
        on error
          set theFiles to (first file of folderDropped whose name extension is in validExtensions) as alias as list
        end try
      end tell

      repeat with thisFile in theFiles
        tell application "Adobe Photoshop 7.0"
          ---- Here it processes the files
        end tell
      end repeat
    end if
  end repeat
end open

On the other hand, you may prefer it without the typos. :wink:

on open droppedItems -- the parameter for an 'open' handler is a list of aliases

  set validExtensions to {"jpg", "gif"} -- add whatever extensions are relevant
  
  -- Cycle through all the dropped items
  repeat with thisFolder in droppedItems
    -- Check that each item is in fact a folder
    tell application "Finder"
      set isFolder to (class of item (thisFolder as string) is folder)
    end tell
  
    if isFolder then
      -- Get aliases to all and any picture files in the folder
      -- ('as alias list' errors if there's only one item)
      tell application "Finder"
        try
          set theFiles to (every file of thisFolder whose name extension is in validExtensions) as alias list
        on error
          set theFiles to (first file of thisFolder whose name extension is in validExtensions) as alias as list
        end try
      end tell

      repeat with thisFile in theFiles
        tell application "Adobe Photoshop 7.0"
          ---- Here it processes the files
        end tell
      end repeat
    end if
  end repeat
end open

It just seems to work great!
BTW, I didn’t realize there were typos…
THX,
Guido