First you need a script. There are countless ways to script things, based on individual skills and knowledge of AppleScript or other languages. For simplicity, let's use automator.

You will want to use the Watch Me Do action to show Automator how to trigger the menu item to lock the screen.

enter image description here

I made this a service, since I like to use FastScripts for something like this. Launchbar will find your service as the top hit if you name it LockScreen as I did in this example when saving from Automator.

(You can make an Application and store it in Apps, but services seem more light weight to me and perhaps a little faster...)

To start, click the record button at the top. Once the screen locks and you get back in, do edit down the action - you can get rid of the "ScreenSaverEngine" task if recorded you getting back in before you stopped the "recording"

I moved the Playback speed to the max. I also told automator that this service receives "no input" just under the record button.

Here is what you should have after saving your new service. Pay attention to the requirements of the Watch Me Do action in the lower left if you have any problems with training your mac to sing itself a short lullaby.

enter image description here


In AppleScript:

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

This doesn't require you to keep the menu bar item.