POSIX error help

I’m trying to build on this script and let it ask for the location of the text file and the location the folders will be built.Just trying to clean this up so others at my place can use it. I keep getting an error on POSIX that the file doesn’t exist. To test this I have a text file named test.txt at the root of Macintosh HD and I tried entering Macintosh HD/test.txt and Macintosh HD:test.txt and both give the error.

This is to build Home folders. I’d also like to have it add a folder named Documents within this folder if it can be done easily but I haven’t a clue how.

I have given up on using chown to change the folder name to the owner because the users don’t exist in the local user database but in LDAP.

I haven’t written scripts since QuarkXpress in 95 and I’m losing hair fast cause lots of things have changed :wink:

thanks for the help, the original script which works is at the bottom as well.

property filelocation : “file location”
property folderlocation : “folder location”

display dialog “Enter location of text file:” default answer “”
set “filelocation” to text returned of result

set namedoc to do shell script “cat "” & (POSIX path of file “filelocation”) & “"”

display dialog “Enter location of Home folders” default answer “”
set folderlocation to text returned of result
set fold to “folderlocation”

repeat with i from 1 to number of paragraphs in namedoc
set this_item to paragraph i of namedoc
if this_item is “end” then exit repeat
do shell script “mkdir -p "” & fold & this_item & “"”
end repeat
display dialog “Done!”

Original script

set namedoc to do shell script “cat "” & (POSIX path of file “OS X Server:usernames.txt”) & “"”

set fold to “/Volumes/OS X Server/homes/”

repeat with i from 1 to number of paragraphs in namedoc
set this_item to paragraph i of namedoc
if this_item is “end” then exit repeat
do shell script “mkdir "” & fold & this_item & “"”
do shell script “chown "” & this_item & " " & fold & this_item & “/” & “"” with administrator privileges
do shell script “chown :!PupilOwner "” & fold & this_item & “/” & “"” with administrator privileges
end repeat
display dialog “Done!”

The posix path of the alias “Macintosh HD:text.txt” is “/text.txt”, if ‘Macintosh HD’ is your startup disk.
Anyway, try using choose file to locate the file.

set file_path to choose file with prompt "Choose the text file:" -- "Macintosh HD:text.txt" as alias
set name_doc to do shell script "cat " & quoted form of POSIX path of file_path -- cat '/text.txt'

set folder_path to choose folder with prompt "Choose the home folders' folder:"

repeat with this_par in paragraphs in name_doc
	if this_par is "end" then exit repeat
	do shell script "mkdir -p " & quoted form of (POSIX path of folder_path & this_par)
end repeat

display dialog "Done!"

Great, that was really what I was trying to accomplish and much cleaner.

How do I add a subfolder called Documents to each of the Home Folders?

I assume I can use the mkdir -p command to make a folder within these folders but I don’t understand the syntax. I need to add an empty Documents folder within the folders created by the above script.

thanks alot, you guys are saving me!

You just need a small change to the ‘do shell script’ line:

choose file with prompt "Choose the text file:"
do shell script "cat " & quoted form of POSIX path of result
set name_doc to result

choose folder with prompt "Choose the home folders' folder:"
set folder_path to POSIX path of result

repeat with this_par in paragraphs in name_doc
	if this_par is "end" then exit repeat
	do shell script "mkdir -p " & quoted form of (folder_path & this_par & "/Documents/")
end repeat

display dialog "Done!" buttons "OK" default button 1

It works great - thanks again!