filtering and copying folder contents names

i want to create an applescript which will run via Automator and filter the contents of a folder and copy the file name of the file ending with “_preview.pdf” so that i can paste that info. Im not sure where to begin and havent found any postings which address this, filtering and copying folder contents.

Dave

Does this work for you?

choose folder with prompt "Get names of preview files from this folder:"

tell application "Finder" to set previewNames to name of every file of folder (result) whose name ends with "_preview.pdf"

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set the clipboard to previewNames as Unicode text
set AppleScript's text item delimiters to ASTID

thank you so much!. it nearly does what i need (which is make it work as part of my automator workflow in contextual menu), i will see if i cant get it work, and will post the results.

Thanks,

Dave

I think I see what you’re trying to do. Do you want this to use the front Finder window instead of making you choose a folder?

tell application "Finder"
	try
		get target of front Finder window
	on error
		get desktop
	end try
	
	set previewNames to name of every file of folder (result) whose name ends with "_preview.pdf"
end tell

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set the clipboard to previewNames as Unicode text
set AppleScript's text item delimiters to ASTID