Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Add users via AppleScript, Perl and expect' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add users via AppleScript, Perl and expect
Authored by: ephantom on Jun 26, '07 11:23:52AM

We are also looking for a way to change the keychain password via command line.


However here is a script we created and use for making new users via command line that others might find helpful:

--------------


#!/bin/tcsh

# Create a New OSX 10.x user

#-------------------------------------------------------------------------------
# Command: ./createuser <First Name> <Last Name> <Short Name> <Uid> <Shell>
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Example: ./createuser Bob Doe bob 520 tcsh
#-------------------------------------------------------------------------------



set first = $argv[1]
set last = $argv[2]
set login = $argv[3]
set number = $argv[4]
set shell = $argv[5]
echo " User's name is ${first} ${last}"
echo " User's login is ${login}"
echo " User's UID is ${number}"
echo " User's shell is /bin/${shell}"

echo " Creating the users account..."

sudo nicl / -create /users/${login} authentication_authority \;basic\;
sudo nicl / -create /users/${login} picture "/Library/User Pictures/Animals/Dog.tif"
sudo nicl / -create /users/${login} _shadow_passwd ""
sudo nicl / -create /users/${login} hint ""
sudo nicl / -create /users/${login} realname "${first} ${last}"
sudo nicl / -create /users/${login} _writers_hint ${login}
sudo nicl / -create /users/${login} uid ${number}
sudo nicl / -create /users/${login} _writers_passwd ${login}
sudo nicl / -create /users/${login} gid 20
sudo nicl / -create /users/${login} shell /bin/${shell}
sudo nicl / -create /users/${login} name ${login}
sudo nicl / -create /users/${login} _writers_tim_password ${login}
sudo nicl / -create /users/${login} passwd \*
sudo nicl / -create /users/${login} _writers_picture ${login}
sudo nicl / -create /users/${login} home /Users/${login}
sudo nicl / -create /users/${login} sharedDir Public

echo " Adding user to the staff group..."
sudo nicl / -merge /groups/staff users ${login}

echo " Creating the users directory..."
sudo ditto -rsrcFork "/System/Library/User Template/English.lproj" /Users/${login}
sudo chown -R ${login}:staff /Users/${login}

echo "Enter the users account password:"
sudo passwd ${login}

echo "Backing up netinfo"
set date = `date +%Y%m%d.%H%M`
sudo cp -pr /var/db/netinfo/local.nidb /var/db/netinfo/local.nidb.${date}

echo ""
echo " Account setup complete."
echo ""



[ Reply to This | # ]