Select files including certain words in the name

I am attempting to combine multiples scripts I’ve found into a usable one that will take the current finder window and current directory and select all files inside that include the text “_alt” or “notondoc”. These folders will contain image files photographed of certain products and I only want to find a quick count for the main images to know if everything has been photographed. I am unsure how to bypass choosing a folder each time as I will already have it open and only want to reference what I already have open in front of me. Any help is greatly appreciated!

tell application "Finder"
	activate
	set the source_folder to choose folder
	set fls to (every file in source_folder whose name contains "_alt" or "notondoc") as alias list
end tell

Hello.

What you are looking for is the target of the front window. (You’ll find them in the dictionary of Finder in As Editor.)

tell application "Finder"
	activate
	set the source_folder to target of front window
	set fls_count to count (every file in source_folder whose name contains "_alt" or "notondoc") 
	display dialog (source_folder as text) & " " & fls_count & " image files." with title "Image Count" buttons {"Ok"} default button 1
end tell

I’m still getting: ““Finder got an error: Illegal comparison or logical.” number -1726” Thank you for your help!

Each expression must be evaluated separately


.
  set fls to (every file in source_folder whose name contains "_alt" or name contains "notondoc") 

Awesome that’s a huge step to get something that doesn’t error out on me! It’s still not quite doing what I had hoped for, it’s pulling up a dialog box and listing files, but is there a way to make finder physically select these files? Or even to just pull up the dialog box with a number rather than having to count the files in the list it displays?

This scripting is so addicting. got it going on my own!

tell application "Finder"
	activate
	set the source_folder to target of front window
	set theFiles to (every file in source_folder whose name does not contain "_alt" and name does not contain "notondoc" and name does not contain "not_on_doc")
	reveal every item of theFiles
end tell

Hello.

I am sorry for the code snippet that didn’t work for you. It worked for me though. :expressionless:

The problem now, seems to be that you have files containing both “alt” and “notondoc”, instead of making an even more elaborate filter expression, I have tried to post process it.

set resultSet to {}
tell application "Finder"
	activate
	set the source_folder to target of front window
	set theFiles to (every file in source_folder whose name does not contain "_alt")
	repeat with aFile in theFiles
		if name of contents of aFile contains "notondoc" then
			set end of resultSet to contents of aFile
		end if
	end repeat
	set theFiles to resultSet
	reveal every item of theFiles
end tell

or as one-liner


tell application "Finder" to select (every file of target of front window whose name contains "alt" or name contains "notondoc")