View Full Version : Copy names of folders, inside a folder and paste to a text doc
Oct 15, 2009, 12:59 AM
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.
Oct 15, 2009, 01:12 AM
1. Open the folder.
2. Select all (command-A).
3. Copy (command-C).
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.
Oct 15, 2009, 05:37 AM
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
Oct 15, 2009, 06:02 AM
Or there is a little free piece of software named "Print Window" that does it very well. Exports to excel, with spotlight comments etc.
Oct 15, 2009, 10:05 AM
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?
Oct 15, 2009, 10:15 AM
You need to go to the Format menu and click "Make Plain Text" before pasting in TextEdit.
Oct 15, 2009, 08:47 PM
Is there any way to do it numerically?
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.
How do I do this off a mounted volume?
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)