Can this be done with Applescript on X?

I am looking for a set of scripts to make a group of folders from a list and make the owner the name of the folder. I basicly want a script that looks to a list of names and makes a home folder for each user than changes the owner to the name of the folder. I have a simple script that works on OS 9 that was written by a college but it refuses to run on an Xserve under 10.4.2.

My second scripting issue is harder, I have a shell script that came from AFP548.com that is supposed to look at an AD group and add the users into an Open Directory group. I have e-mailed the author because after filling in my info, it runs but generates an error and never populates the OD group. I suspect there are differences from 10.3 to 10.4 in shell. Has anyone tried to do this type of script or anything similar in Applescript I could model after?

I am new to Applescript use in the OS, I have some background with older scripts in Quark.

thanks for any input.

please post an example of the list

The file to import is a simple short name list such as:
anbroz01
acgabs01
absmat01
acjone02

this is exported from AD, we would first need to create the home folders and then set the owner. The previous script used under OS 9 to create home folders was:

set theFileReference to open for access file “Server HD:usernames”
set theUsername to “”
repeat until theUsername = “end”
set theUsername to read theFileReference before ASCII character 9
read theFileReference until ASCII character 13
tell application “Finder”
make new folder at folder “User” of disk “XRAID” with properties {name:theUsername}
end tell
end repeat
–close access theFileReferece/

then we would run:

set theDisk to (choose folder)
set usernames to list folder theDisk as text

repeat with foldername from 1 to number of items in usernames
–repeat with foldername from 1 to 3
tell application “Finder”
activate
try
select folder foldername of disk theDisk
set username to name of selection as text
open sharing window of selection
set inherited privileges of selection to false
set owner of selection to username
–set group of selection to “!PupilOwner”
close sharing window of selection
on error
–beep
end try
end tell
end repeat

to set the folder owner. I thought it would run under OS X however we are get a looping error. Has some major syntax been changed from 9 to 10?

thanks for any input, sorry I didn’t provide more detail.

Unix is fun…
Let me know how this works (it should do what both script did). I’ll commit myself to helping you.
If it ends up you are typing in your password a billion times I’ll find a fix.

set namedoc to do shell script "cat \"" & (POSIX path of file "Server HD:usernames") & "\""

set fold to "/Volumes/XRAID/User/"

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!"

I tried to test it over the weekend by using my 10.3.9 server. I made a folder named homes at the root of the hard drive. The HD is names OS X Server. THen I modified the script to use it and tried using the Volumes command and not using it, either way all I got was a folder created named 'X" at root of the hard drive and an error.

This is the modified script, I tried it with and without “Volumes” in place

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 error says
mkdir: /OS:File Exists
mkdir: X:File exists
mkdir: Server/homes;no such file or directory

it went down to line to the line below before making the error.
do shell script "mkdir " & fold & this_item

All I get is a folder named X for some reason.

thanks, I’ll ve watching for messages

silly me. try this

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!"

Getting warmer, its making the home folder then erroring on:

do shell script “chown "” & this_item & " " & fold & this_item & “/” & “"” with administrator privileges

usage : change owner {priveleges}

thanks

Macgeek’s got you real close.

I try to get the shell script good before I take it into a script.

Change

do shell script “chown "” & this_item & " " & fold & this_item & “/” & “"” with administrator privileges

to

Set x to “chown "” & this_item & " " & fold & this_item & “/” & “"”
Log x

Then cut the x string out of the event log and try running it in terminal. Debug it there. The problem usually jumps right out.

Yowzah, I’m crazy. Sorry for the mistakes. try this…

do shell script “chown " & this_item & " "” & fold & this_item & “/” & “"” with administrator privileges

Still makes 1 folder with 1 name and now the error is
chown:anzb01:Invailid Argument

on line:
do shell script “chown " & this_item & " "” & fold & this_item & “/” & “"” with administrator privileges

this is the first name on the list, the error is on the same line, I’m going to rem out some stuff to see if I can get my folders built with it while we work out the privileges, school starts tomorrow.

I tried it earlier on the XRAID and got invalid arugment; PupilOwner

got 1 folder there too but it did make it past the line on the 10.4.2 server, 10.3 here at home.

I just dropped the chown commands and it made all 460 folders on 1 server.
I don’t mind 2 scripts, isn’t it easier to read the folder name and make it the owner with a seperate shell script?

were these users already created in the OS?
if not then this would fail

They don’t exist in the Net Info, they are imported from Active directory into an Open Directory group but don’t have individual accounts on the server. I thought that may be an issue.

So where do I go from here? I have 1000-1500 users in these groups over 5 servers. If I add them all locally, it’ll be a nightmare.

I can let the OS X machines build their own home folders after reading the path from AD but the Mac manager users don’t create the home folder correctly under 10.4.2 server, thus this scripting issue.

well, I don’t know how to help. I’m sorry.
I don’t know a thing about AD or Mac servers.

well, we have folders. We’ll map to the drive from an OS 9 box and run the old script, for some reason it does work.

If I do this, where is the log? I really want this to work
thx