Drop a folder, get a list of it's contents in the clipboard

Seems simple, but none of the simple attempts are working.

This is what I have been using and just running it from Script Editor, then copying the output from the result window:

tell application "Finder"
	set the_list to the name of every item in the front window
end tell

I’ve tried probably a dozen variations of stuff I’ve read on this forum, here was my best and last attempt:

on open docList
	tell application "Finder"
		set theList to name of every file of folder docList
		set the clipboard to theList
	end tell
end open

I also tried things along this line:

on open docList
	set runningNameList to ""
	repeat with x from 1 to number of items in docList
		tell application "Finder"
			set theFile to item x of docList
			set theName to name of theFile
			set runningNameList to runningNameList & return & theName
		end tell
	end repeat
	set the clipboard to runningNameList
end open

Any ideas?

Something like this:

on open docList
	set dl to docList as alias
	set FNames to ""
	tell application "Finder"
		set theList to name of every file of folder dl
		repeat with aFile in theList
			set FNames to FNames & aFile & return
		end repeat
		set the clipboard to FNames
		-- display dialog FNames
	end tell
end open

hi adam,

nice script. might i add some error correction and a method for use when double clicked?


on open docList
	set docFolder to POSIX path of docList
	if docFolder ends with "/" then
		setClip(docList)
	else
		display dialog "This program only works with folders."
	end if
end open

set docList to (choose folder)
setClip(docList)

on setClip(docList)
	set dl to docList as alias
	set FNames to ""
	tell application "Finder"
		set theList to name of every file of folder dl
		repeat with aFile in theList
			set FNames to FNames & aFile & return
		end repeat
		set the clipboard to FNames
		display dialog FNames
	end tell
end setClip

Neat, and better.

Beautiful work. Thanks for a solution and some good code to chew over!

:smiley:

Hi,

Another way is to coerce list to string. Something like this:


set f to choose folder
tell application "Finder"
	try
		set f_list to (every item of f) as alias list -- list of AppleScript paths
	on error
		set f_list to (first item of f) as alias as list
	end try
	-- set f_list to (name of every item of f) -- for list of names
end tell
set def_tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return}
set f_text to f_list as string
set AppleScript's text item delimiters to def_tid
return f_text

I didn’t use the open handler, but it’s easy to change to droplet. I didn’t do speed test yet also. Still reading the other new posts.

gl,