The title is a little bit confusing, however I wanted to convey a meaning title for this post. If you are ever into using the Fast User Switch, located under your name on the right hand side of the menu bar you will notice that there is no short cut associated with it. If you are mindful about security of your account while at home or at work, switching to the log in menu is a great way to stop people from accessing your account, since people need a password to log in to do some damage. This post will show you a Terminal command to Fast User switch and how you can apply this code to a Services menu (to allow you at attach a keyboard short cut) and a Terminal script.
First, the script. If you open up Terminal located in Applications > Utilities and copy and paste the following, your Mac will take you to the log in screen (and still keep you logged in).
'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend
As a Terminal command its useful for working into your scripts, but as a general user its not that complicated, and you can’t add a keyboard short cut that easily. So we are going to create a services menu. Services menus allow you to apply a keyboard short cut through System Preferences.
Following a similar tutorial on iTunes from earlier this week, open Automator in Applications. This will only work on the latest version of OS X, 10.6. Within Automator select Service from the pop up menu. At the very top of the workflow select “no input” from the first drop down menu. Then add a “Run Shell Script” from the library of actions, its under Utilities. Copy and paste the code into the box and save the Service menu option with a memorable and useful name.
When you have saved the script, test it out from the Services menu under the application name you are currently running. If you want to add a short cut, go to System Preferences > Keyboard > Keyboard Shortcuts > Service (left hand column) and select your Service from the bottom of the list. Double click the far right of the option and enter a keyboard shortcut. I recommend two modifier keys (eg Command and Option). You could emulate Windows with Command + L, however other applications may have used this shortcut. Give your operating system a minute or two to update the various databases and allow the short cut to propagate and you can then test it out. Useful or what?
You can of course use this command for nearly anything, if you are handy with shell scripts it goes well at the end of a script you may be running. You can do various other things with the command, the best way to learn more is to Google the string (excluding the -suspend). You can log in other users quickly and easily with this command, it just takes a little bit of work and patiences to set up.
Please leave a comment below if you have found this command useful and please share what you have done with it.