On Mar 27, 2014, at 2:03 PM, Luther Fuller <
email@hidden> wrote:
My problem continues to evolve.
After an analysis of the way my script should be used, I have concluded that a Standard user should run the script only if he can supply an ADMIN username and password.
(My script, called "Cloaking Device", makes disk partitions invisible, so I can show on the desktop only those disks I need to see. It also allows a user to make the user's Library folder visible.)
As far as I can determine, there simply does not exist a dialog that allows entry of username and password and returns its exists on the computer. I have looked for a shell command that does this, but no luck.
Does anyone know of such a shell command ?
Asking for a username and password, and then checking them for validity in a separate step, is very definitely the WRONG WAY TO DO IT™. Your script should never see an actual password. Exposing a password in the clear like that would be a huge security violation.
What you can do is invoke
do shell script ... with administrator privileges
When you do that, the system will put up an authentication dialog, securely collect a username and password, and without telling you the password determine whether it is correct. If it is correct, the supplied script will be executed with root privileges. (Not admin privileges, despite the name. Actual root privileges. As such, the script need not and should not invoke sudo.)
Making the current user's Library folder visible does not require admin (nor root) privilege. The user owns their own Library folder, and does not need an admin's blessings to make it visible. Nor would it be proper for any user, even an admin, to futz around with another user's Library folder. (An admin could do that, but only by escalating to root privileges using sudo. That should be your clue that it's the wrong way to do it.)
To make your own Library folder visible:
tell application "System Events"
set the visible of library folder of user domain to true
end tell
Making disks invisible strikes me as awfully heavy-handed. Are you really sure you want to be doing this? Remember that your script is not the center of the user's universe. Making a disk invisible is permanent until explicitly undone. It will affect all users, not only on this machine but on any machine the disk is ever connected to. It will affect everything else your current user is doing. It will persist across logouts, restarts, and even shutdown.