Is there a way to build an AppleScript for locking the screen? I want to add a Quick Action (and the relative button on the Touch Bar as described here)
This solution i.e.,
tell 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
does not work in Catalina. After allowing accessibility for Apple Script Editor from Security and privacy, I still get this error in automator:
Can’t get menu 1 of menu bar item 2 of menu bar 1 of application process "SystemUIServer". Invalid index.
tell application "System Events" to keystroke "q" using {control down, command down}
worked like a charm. If you want to add an answer I'm going to accept it. Thanks! – floatingpurr Feb 06 '20 at 15:06tell application "System Events" to click menu item "Lock Screen" of menu 1 of menu bar item "Apple" of menu bar 1 of application process "Finder"
does not work – floatingpurr Feb 06 '20 at 15:39application process ...
. – user3439894 Feb 06 '20 at 16:48