Applescript to prompt for a password

I’m trying to generate a script that will prompt a user for the currently logged-in administrator’s password when it’s run, locking the screen if it’s not typed in correctly, and doing some UI scripting wizardry if it is. Is there any way to do this (besides the UI scripting, which I can figure out with enough time and caffeine)?

I dunno if this is asking for just the current admin or any admin, but it’s what I hobbled together from looking at other threads:

try
	do shell script "echo ''" with administrator privileges
	display dialog "Authenticated!"
	-- your UI scripting wizardry
on error
	do shell script "open '/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app'"
end try

My god that was helpful. Thank you so appallingly much! It works perfectly!

Well, it’s working to 99% satisfaction, but the password dialog has a habit of throwing an error if it’s left for too long. I’d just set a timeout value, but what I’d really like to happen is for it to automatically enter the screen saver if it’s left for, oh, say, 10 seconds. Is there a way to force this to happen after ten seconds of dialog box? Thanks again.

When I used a timeout value and a tell statement, the screen saver activated after 10 seconds. The authentication dialog was still up when I exited the screen saver, but it appeared to be orphaned from the script at that point because clicking ‘cancel’ did nothing.

try
	with timeout of 10 seconds
		tell application "System Events" to do shell script "echo ''" with administrator privileges
	end timeout
	display dialog "Authenticated!"
	-- your UI scripting wizardry
on error
	do shell script "open '/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app'"
end try