List Files of Chosen Folder

This AScript works in OS9. Now in OSX I get the following error message: “Finder got an error: Unknown object type.”

This script originally came from “Sal’s AppleScript Snippets” at (Thanks Sal!)

What is going on, and how do I fix it? We need this because OSX got rid of the Print Window command.

tell application "Finder"
	set theFolder to choose folder
	set theList to (every file of theFolder) as list
	set theList to (sort theList by name) as list
	set defaultNameList to "Every file of folder: " & (name of theFolder)
	set theNameList to defaultNameList
	repeat with thisItem in theList
		set theNameList to theNameList & return & name of thisItem
	end repeat
end tell

if theNameList is defaultNameList then
	display dialog "No files found." buttons {"Cancel"} default button 1
end if

	set the clipboard to theNameList
	beep 2
on error
end try

Thanks in advance for your consideration.

Hi hripka,
I’m not sure but I think the “sort list” feature is not available in X without using third parties scripting additions, so may be this line

set theList to (sort theList by name) as list 

is the one that makes trouble.

Good scripting

Yes, this is from Finder’s dictionary:


And this could be a OSX quick replacement:

set the clipboard to (do shell script "find " & quoted form of POSIX path of ((choose folder)) & "* -prune -type f -exec basename {} \;")