Tuesday, February 9, 2010

#1 2006-07-19 03:56:18 pm

waltr
Member
Registered: 2005-09-13
Posts: 314

Change AutoLogin from AppleScript

hello,

this grew out of an idea i had after reading this post:

http://bbs.applescript.net/viewtopic.php?id=14141

it will give you a list of 'users' and let you pick the one you want to have 'autoLogin' when you start the computer.  hopefully this will be useful to someone:

Applescript:


set getUsers to (do shell script "/usr/bin/nireport / /users name uid | grep \"5[0-9][0-9]\"")

set howMany to number of paragraphs in getUsers
set theUsers to {missing value}
set i to 1
repeat while i ≤ howMany
   if i = 1 then
       set theUsers to word 1 of paragraph i of getUsers as list
   else
       set theUsers to (theUsers & word 1 of paragraph i of getUsers)
   end if
   set i to (i + 1)
end repeat

set autoLoginUser to (choose from list theUsers)

if autoLoginUser is not false then
   do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser " & autoLoginUser with administrator privileges
   display dialog "User " & autoLoginUser & " is now the default Auto Login."
end if


I use Google or any search engine to find out things I don't know!

Offline

 

#2 2006-07-19 06:20:01 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4175

Re: Change AutoLogin from AppleScript

Slick Waltr. So slick that I've moved it to Code Exchange


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.2

Offline

 

#3 2006-08-02 02:06:45 pm

waltr
Member
Registered: 2005-09-13
Posts: 314

Re: Change AutoLogin from AppleScript

hello,

i found a bug in the code for this.  the new code also adds the UID of the autoLoginUser:

Applescript:

set getUsers to (do shell script "/usr/bin/nireport / /users name uid | grep \"5[0-9][0-9]\"")

set howMany to number of paragraphs in getUsers
set theUsers to {missing value}
set i to 1
repeat while i ≤ howMany
   if i = 1 then
       set theUsers to word 1 of paragraph i of getUsers as list
   else
       set theUsers to (theUsers & word 1 of paragraph i of getUsers)
   end if
   set i to (i + 1)
end repeat

set autoLoginUser to (choose from list theUsers)

if autoLoginUser is not false then
   set userInf to (do shell script "/usr/bin/nireport / /users name uid | grep " & autoLoginUser)
   set userNum to word 2 of userInf
   do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser " & autoLoginUser with administrator privileges
   do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUserUID " & userNum with administrator privileges
   display dialog "User " & autoLoginUser & " is now the default Auto Login."
end if

it seems to work better.  as always, comments welcome.


I use Google or any search engine to find out things I don't know!

Offline

 

#4 2007-01-02 06:17:39 pm

carrie
Member
Registered: 2007-01-02
Posts: 2

Re: Change AutoLogin from AppleScript

Thanks guys, I have used your advice to create a couple of scripts that enable & disable autologin, to use when auto-deploying a mac lab.

To enable autologin, I created an applescript, which calls the following shell scripts:

/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser yourusername
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUID yourUIDnumber

I found that I also needed the kcpassword file (/private/etc/kcpassword) - to get this, enable autologin manually in system preferences, then make a backup of this file and keep in a separate location, then copy back to its original location as part of your script, eg:

cp /Path/To/Backup/kcpassword /private/etc/kcpassword

And to disable autologin (in our lab, this is part of a shell script that gets run as a loginhook):

/usr/bin/defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser
srm /private/etc/kcpassword

Hope this helps someone?

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.313 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)