Copying file name(s) to clipboard with automator

Hi, this is my first post here, so I hope i’m not being redundant (I am also VERY new to applescript).

I need to copy file name(s) to the clipboard with automator without the path.
I have used the “Get Folder Contents” command, but I get the whole path when its pasted to TextEdit.

I have successfully used this modified applescript from one that I found here previously:

set f to (choose folder)
tell application "Finder" to set e to name of items of f
if e = {} then
	beep
	display dialog "No items found in the folder "" & f & ""." buttons {"Cancel"} default button 1 with icon 0 giving up after 10
else
	set filelist to {}
	repeat with i from 1 to (count e)
		set end of filelist to ("" & e's item i & ", " & return)
	end repeat
	set the clipboard to "" & filelist
	beep 2
end if

But this uses a choose folder command. Ideally I could use this same applescript in line with automator if I knew how to make this receive the folder from the previous step instead of the choose folder command.

any help appreciated

thanks

Daniel

Moving this to the Automator forum.

Try something like this:

on run {input}
	set filenameList to {}
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {", "}
	
	tell application "Finder"
		launch	
		repeat with thisFolder in input
			set filenameList's end to (name of every item of thisFolder) as Unicode text
		end repeat
	end tell
	
	set AppleScript's text item delimiters to {ASCII character 10}
	set the clipboard to filenameList as Unicode text
	set AppleScript's text item delimiters to ASTID
	
	return {input}
end run

This should seperate the filenames with commas. If multiple folders are passed to the script, then each folder’s filenames will be on a seperate line (that’s where “ASCII character 10” is used).