Copy names of folders, inside a folder and paste to a text doc

Discussion in 'Mac Programming' started by laynef, Oct 14, 2009.

  1. laynef macrumors newbie

    Oct 14, 2009
    Hi, I'm trying to write an applescript to help me archive. I need a script to copy the names of the folders (which are jobs) and paste them into a text file.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    In Finder:
    1. Open the folder.
    2. Select all (command-A).
    3. Copy (command-C).

    In TextEdit:
    4. Open a new or existing document.
    5. Paste (command-V).

    It took me at least 10 times longer to write this than to perform the actions.

    Do you really need to write a script? Are these actions going to be performed repeatedly, without human intervention?

    If you need a script, try this example:

    list folder (path to home folder)
    Paste it into Script Editor and run it. Note that it returns a list. So walk the list, or remove its first item until it's empty, appending each name to a string. Finally, write the string to a file.

    If you can't figure it out from the example, please describe your scripting experience, and whether it needs to list the contents of a certain fixed folder, or the contents of any folder you choose.
  3. mysterytramp macrumors 65816


    Jul 17, 2008
    You don't need to walk the list. This will return a return-delimited list:

    set dummyList to list folder (path to home folder)
    set TID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to return
    set dummyList to dummyList as text
    set AppleScript's text item delimiters to TID
  4. Angelo95210 macrumors 6502a


    Jan 7, 2009
    Paris, France
    Or there is a little free piece of software named "Print Window" that does it very well. Exports to excel, with spotlight comments etc.
  5. laynef thread starter macrumors newbie

    Oct 14, 2009
    Ok the copy and paste didn't work, it just pasted the folder icons into a text document. I tried the other script and that worked, although it made the of text go from 10,11,12,13,14,2,3,4,5,6,7,8,9. Is there any way to do it numerically? It doesn't matter that much, my next question is I can get it work on my local computer by using the path "Macintosh_HD:Users:admin:test"
    Where Macintosh_HD is my computer and test is the folder I want to get the names out of. How do I do this off a mounted volume? I can't get it read off of there. This is what the path would be using UNC \\xraid1\Rsi Jobs.standby
    my other question is there is a space in the folder name, will it let me use the name with a space?
  6. Darth.Titan macrumors 68030


    Oct 31, 2007
    Austin, TX
    You need to go to the Format menu and click "Make Plain Text" before pasting in TextEdit.
  7. mysterytramp macrumors 65816


    Jul 17, 2008
    If you add the leading zero to the file name, it will:

    01, 02, 04=3, 04 ,05, 06, 07, 08, 09, 10, 11, etc.

    but if the files are named 1, 2, 3, 4, ... you'll get what you found.

    You have a couple of options. You can hard code the path:

    set dummyList to list folder ("Volume name:First Folder:Second Folder:Third Folder") -- see? it works with spaces

    You can also use a Posix path:

    set dummyList to ("/Library/Contextual Menu Items/")

    or you could give yourself more options by saying:

    set dummyList to list folder (choose folder)


Share This Page