Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

laynef

macrumors newbie
Original poster
Oct 14, 2009
2
0
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
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:

Code:
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.
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
You don't need to walk the list. This will return a return-delimited list:

Code:
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
dummyList

mt
 

laynef

macrumors newbie
Original poster
Oct 14, 2009
2
0
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?
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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)

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.