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.
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.
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…
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.