Answers:
Keychain Access。打开这个Show Status in Menu BarAutomator。选择这个ServiceRun Applescript在Actions和Variables按钮旁边搜索。双击此Service receives no input in any applicationtell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 of menu bar 1 where description is "Keychain menu extra")
click
click menu item "Lock Screen" of menu 1
end tell
end tell
将此Automator保存为类似Lock screen(注意:GIF中的代码是不同的!)

捷径:
System PreferencesKeyboardKeyboard Shortcuts标签Services在任何应用程序中使用您的快捷方式!

要么...:
System Events got an error: Can’t get menu 1 of menu bar item 2 of menu bar 1 of application process "SystemUIServer". Invalid index.
macOS 10.11 El Capitan 使用AppleScripts 似乎无法解决,的问题,但是我发现,如果我安装了Lock Screen并使Automator Service打开其“ Lock Screen Bundle”,则其余过程按预期工作(假设我叫服务是“锁定屏幕”,而不是“锁定屏幕”:文件名中的空格显然会破坏许多macOS用户的键盘快捷键)。
有关图示的逐步指南,请参见Mac OS X上的“锁定屏幕快捷方式”。
我为此有一个简单的衬板。它使用系统事件发送“锁定屏幕”命令的默认键组合,并且可以在High Sierra(10.13)及更高版本的OSX的所有版本中使用。甚至莫哈韦!尽管会提示您为该应用提供其他安全权限,但在较新的OSX版本中
tell application "System Events" to keystroke "q" using {control down, command down}
我使用宏接受快捷键Command-L。最近从Windows切换到Mac,锁定屏幕的简便方法非常重要。在Windows中,只需按Windows键和L,然后锁定即可。
使用Keyboard Maestro,我为快捷键Command-L创建了一个宏,该宏基本相同(将Command键与Windows键进行比较)。该快捷方式触发功能“登录窗口”,该功能锁定屏幕。至少对我来说容易。
(在Keyboard Maestro中,“登录窗口”功能位于“操作”>“系统控制”下。)
对于High Sierra(10.13),无法接受答案,因为“钥匙串访问”没有Check Show Status in Menu Bar选择。但是,基于无私掠夺Lockscreen App的源代码(如@Alice Purcell所述),我发现了这个漂亮的GUI脚本解决方法:
activate application "SystemUIServer" tell application "System Events" tell process "SystemUIServer" to keystroke "q" using {command down, control down} end tell