I know this has been discussed before but forgive me because after hours of searching this site, I can’t find the answer I need.
I’m looking for a script that will simply allow me to choose a folder of files, copy each file and then write it to a text file (though just going to the clipboard would be fine, too).
I tried to modify a script by T.J. Mahaffey that was originally written for OS 9, but I can’t make it work in X.
Does the script in this thread do what you want it to do? Here’s the code:
set output_ to (choose file name with prompt "Choose a name and location for the new file.")
set folder_ to (choose folder with prompt "Select the folder containing the text files.")
tell application "Finder" to set files_ to files of folder_ as alias list
try
set file_ref to open for access output_ with write permission
repeat with file_ in files_
set text_ to read file_
write (text_ & return) to file_ref starting at eof
end repeat
try
close access file_ref
end try
on error e
display dialog e
try
close access file_ref
end try
end try
Not quite what I was after. I just need the filenames of the files, I don’t need the whole file copied. I didn’t make that very clear in my first post.
So if I have a folder of images 001.jpg, 002.jpg, 003.jpg my text document would just be a list of those filenames (preferrably separated by a return):
001.jpg
002.jpg
003.jpg
set output_ to (choose file name with prompt "Choose a name and location for the new file.")
set folder_ to (choose folder with prompt "Select the folder containing the files whose names should be collected.")
tell application "Finder" to set files_ to files of folder_ as alias list
set names_ to ""
repeat with file_ in files_
set names_ to names_ & (name of (info for file_) & return)
end repeat
try
set file_ref to open for access output_ with write permission
write names_ to file_ref starting at eof
try
close access file_ref
end try
on error e
display dialog e
try
close access file_ref
end try
end try
Here’s an alternate method that is a bit quicker but has the downside of not filtering out folder names (Rob’s solution will only grab file names) though if your folder only has files, this issue is moot: