Q: How can I copy a list of filenames in finder and set the clipboard to the filenames separated by comma?
Hi guys, I wonder if someone can give me a hand with a script.
I need to be able to paste a list of filenames of picture files as follows:
0001.jpg, 0002.jpg, 0003.jpg, 0004.jpg
At the moment if I select the files in Finder, copy to clipboard and paste them to TextEdit they are like that:
0001.jpg
0002.jpg
0003.jpg
0004.jpg
I found a similar script but a bit different and I'm not sure how to change it. Here it is:
set extension_list to {"jpg", "JPG", "jpeg", "JPEG"}
set cbNames to paragraphs of (the clipboard as text)
set csvNames to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
-- now make a list of names without extensions
repeat with names in cbNames
if text item 2 of names is in extension_list then
copy text item 1 of names to the end of csvNames
end if
end repeat
log csvNames
-- now concatenate filenames as comma separated string
set AppleScript's text item delimiters to ","
set theData to csvNames as text
set AppleScript's text item delimiters to tid
iMac, OS X El Capitan (10.11.6)
Posted on Aug 24, 2016 2:05 AM
Hi Roger,
thanks very much for the idea, but I'm trying to avoid the quantity of steps to achieve that. I already managed to do it with a script and this works as on click on the application created from script editor. I placed a shortcut on the dock and everything is quick. I will paste my script. I'm sure that the script can be improved and I'm open for suggestions.
set extension_list to {"jpg", "JPG", "jpeg", "JPEG"}
set cbNames to paragraphs of (the clipboard as text)
set csvNames to {}
--Make sure we are copying only jpg's
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
-- now make a list of names
repeat with names in cbNames
if text item 2 of names is in extension_list then
copy names as text to the end of csvNames
end if
end repeat
set AppleScript's text item delimiters to ", "
set the clipboard to csvNames as string
Posted on Aug 24, 2016 2:47 AM


