Going to Login Window Automatically

Ciao all,

I need to write a script that will lock my machine after a certain time.
I thought if i can write a script that calls the login window but i cant find anything related to that topic.
Note that i dont want to log off i just want to lock and keep everything running.

Anyone knows…

tony

Hi Tony,

I don’t think you need an Applescript to do this.

If you mean after a period of inactivity, you can set the computer to go to sleep after a set time in System Preferences> Energy Saver and set it to need a password to awake from sleep in System Preferences> Security.

If you mean to sleep after a time of day look at System Preferences> Energy Saver> Schedule… You can set the computer to sleep instead of shutting down.

Best wishes

John M

hi john,
i applied what you told me, but it seems then after waking up it is not prompting for a password…actually i m logged in as a root user.
what can i do in that case…

Very bad idea to have your normal working environment as root. You should be logged in as Administrator. Then this solution works.

Try this:

do shell script “/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend”

Hi,

You can also add an icon to the menu bar with a menu item to lock the screen at any time. Open up the app “Keychain Access”. Under the View menu, select Show status in menu bar.

gl,