Help with Applescript to create a local user

I have an Applescript that creates a user account on Mac OS X 10.7 but will not create the home folder. So when I login with the new user account, it yells at me that there is no home folder. I’ve tried other solutions I’ve seen on the interwebs, but with no luck. I’m still somewhat of a newb to Applescript and Macs, so I may be looking over something really simple. Here’s the script and what I’ve tried:


set shortUser to "testuser"
set longUser to "Testing User"
set userID to "1001"
set groupID to "staff"
set userPass to "test-123"

set theCommand to ""

set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & ";"
set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " UserShell /bin/bash;"
set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " RealName " & quoted form of longUser & ";"
set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " UniqueID " & userID & ";"
set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " PrimaryGroup " & groupID & ";"
set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " NFSHomeDirectory /Users/" & shortUser & ";"
set theCommand to theCommand & "/usr/bin/dscl . -passwd /Users/" & shortUser & space & userPass & ";"
set theCommand to theCommand & "/usr/bin/dscl . -append /Groups/admin GroupMembership " & shortUser

do shell script theCommand with administrator privileges


I have tried changing:

set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " NFSHomeDirectory /Users/" & shortUser & ";"

to

set theCommand to theCommand & "/usr/bin/dscl . -create /Users/" & shortUser & " home /Users/" & shortUser & ";"

No success. I’ve also tried running each of the following commands with no success:


do shell script "sudo createhomedir -c -u testuser" with administrative privileges
do shell script "sudo createhomedir -l -u testuser" with administrative privileges
do shell script "sudo createhomedir -c" with administrative privileges
do shell script "sudo createhomedir -l" with administrative privileges

Whatever I do, I don’t see a folder “testuser” in the /Users/ directory, am I looking in the wrong place? All the other information seems to be working, I’m just having the home folder issue.

Thanks in advance.

dscl does not create the home folder, it only makes an entry in its database.

Don’t use ‘sudo’ and ‘with administrative privileges’ in the same command: it will fail. The 2nd phrase will do.

Did you see this? Also follow the link given there - you’ll find a shell script to do this.

thanks alastor, that worked…I found the ‘chown’ command yesterday and was able to get everything going.

Hi, so I’m trying to do exactly the same thing. I’m getting the account created but not the home directory. I’ve tried everything on this post and others but am missing something obvious. How did you get it to work in the end?