Several people here have worked on a script I needed for a school system to create home folders for the students. The script is below and works well. As part of the automation, the script needs to set the owner to the name of the folder. These users do not have local accounts but do exist within the LDAP(OpenDirectory) groups. How do I add a shell chown line to this to make the folder name the owner name? I’ve tried several variants of chown with no success. This would also allow me to schedule a variation of the script in the cron.
set file_path to choose file with prompt “Choose the text file:”
set name_doc to do shell script "cat " & quoted form of POSIX path of file_path
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 (folder_path & this_par & “/Documents/”)
end repeat
display dialog “Done!”
Not sure I understand since I missed your previous posts about this project. When you say “How do I add a shell chown line to this to make the folder name the owner name?”, do you mean “make the folder’s owner the same the folder’s name?”
I saw that but the answer assumes you know the name of the folder and I don’t. Yes I want to make the folder name the folder owner. I understand the basic command but I’m lost, especially with shell and I don’t know the syntax to get the chown command to read the folder that was created on the line above it. There will be several of these folders with hundreds of folders within of user names so the path will change to the folder as well.
thx for the fast reply
Yes it is but how do I word it? In other words would it be something like:
do shell script “chown -R” quoted form of (folder_path & this_par & “/Documents/”) quoted form of (folder_path & this_par & “/Documents/”)
I get to the second quoted form and get a syntax error “Expected end of line but found property’”.
I was trying
do shell script “chown -R” quoted form of (folder_path & this_par & “/Documents/”) quoted form of (folder_path & this_par & “/Documents/”) with administrative privileges
set thePath to quoted form of (folder_path & this_par & “/Documents/”)
set theOwner to this_par
set theScript to "chown -R " & theOwner & " " & thePath
set file_path to choose file with prompt “Choose the text file:”
set name_doc to do shell script "cat " & quoted form of POSIX path of file_path
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 (folder_path & this_par & “/Documents/”)
set thePath to quoted form of (folder_path & this_par & “/Documents/”)
set theOwner to this_par
set theScript to "chown -R " & theOwner & " " & thePath
do shell script theScript with administrative privileges
end repeat
display dialog “Done!”
Generates a syntax error on the word priviliges "Expected end of line, etc. but found identifier - and stops -more ideas?
set file_path to choose file with prompt “Choose the text file:”
set name_doc to do shell script "cat " & quoted form of POSIX path of file_path
set folder_path2 to choose folder with prompt “Choose the home folders’ folder:”
set folder_path to POSIX path of folder_path2
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
repeat with this_par in paragraphs in name_doc
set thePath to folder_path & this_par & “/Documents”
set homepath to folder_path & this_par
set theOwner to this_par
set theScript to "chown -R " & theOwner & " " & quoted form of (homepath)
do shell script theScript with administrator privileges
end repeat
display dialog “Done!”
This is actually a nice useful script for any server admin, it creates the home folder and the document folder then changes ownership to the name on the folder.