2

I would like to turn the contents of a folder into entries for Numbers (or Excel) - is there a way to automate doing this?

  • Just the filenames or addititional information (size, creation date etc) as well? – nohillside Apr 5 '14 at 4:49
  • Just the filename is my immediate need - thank you! – EyeOjO Apr 5 '14 at 4:56
1

You can use Automator.app to create a service in finder.

Open Automator.

  • Create a new service documents
  • set the the service receives selected Folders in Finder
  • Add a Get folder contents Action.
  • Add a Get Run Applescript Action.

  • replace the applescript content with the applescript below.

.

on run {input, parameters}
    set theCsv to ""
    repeat with i from 1 to number of items in input
        tell application "Finder" to set this_item to displayed name of item i of input
        set this_item to this_item & ",\\n"
        set theCsv to theCsv & this_item
    end repeat
    do shell script "echo " & quoted form of theCsv & " > ~/Desktop/names.csv"
end run

enter image description here

  • save the document

Now when you select a folder in finder you can use the contextual menu to run the service on the folder.

It will create a .csv file on your desktop of the list. Which will open in Numbers.

Note: if you have more than one folder it will create a single list for both. It is possible to have it only work on the first folder or both individually


UPDATE:

A quick applescript example to work on multiple folders in selection. This will create a individual file for each directory in the finder selection

    on run {input, parameters}
        set theCsv to ""

        set pathList to {}
        repeat with i from 1 to number of items in input
            tell application "Finder" to set the Cpath to container of item i of input as alias
            if (Cpath as alias) is not in pathList then
                copy Cpath to end of pathList
            end if
        end repeat


        repeat with a from 1 to number of items in pathList
set this_item to item a of pathList
    set thisFileName to ""
        tell application "Finder" to set thisFileName to displayed name of (this_item as alias)

            set the CSVpath to ""
            repeat with i from 1 to number of items in input

                tell application "Finder"
                    set the Cpath to container of item i of input as alias

                    if container of item i of input as alias is this_item then
                        set theName to displayed name of item i of input & ",\\n"
                        set CSVpath to CSVpath & theName

                    end if
                end tell
            end repeat

     do shell script "echo " & quoted form of CSVpath & " > ~/Desktop/" & quoted form of thisFileName &  ".csv"
        end repeat


    end run

UPDATE 2. This second example now uses the folder name as the name for the file

|improve this answer|||||
  • That is great and functional, is it possible to tweak the code so that the name of the output .csv is the same as the input folder name? – EyeOjO Apr 5 '14 at 15:10
  • yes. give me a min – markhunte Apr 5 '14 at 17:15
  • @EyeOjO , done (second example only) – markhunte Apr 5 '14 at 17:32
0

The easiest (but somehow manual) way is to select all the files in Finder, copy them to the clipboard with Cmd-C and then pasting the names into a Numbers sheet with Cmd-V.

If you want more control, you can revert to Terminal for the copy step and run

cd /some/folder
ls *.jpeg | pbcopy

to get the name all jpeg files in this folder into the clipboard.

|improve this answer|||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .