Skip to main content
added 502 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

You can use:

tell application "System Events" to keystroke "q" using {control down, command down}

You could also use the following instead:

tell application "System Events"
    set appName to (name of every application process whose frontmost is true and visible is true) as string
    click menu item "Lock Screen" of menu 1 of menu bar item "Apple" of menu bar 1 of application process appName
end tell

      Hint: Mouse over and horizontal/vertical scroll to see full code.

However, the first mentioned solution is more direct.

You can use:

tell application "System Events" to keystroke "q" using {control down, command down}

You can use:

tell application "System Events" to keystroke "q" using {control down, command down}

You could also use the following instead:

tell application "System Events"
    set appName to (name of every application process whose frontmost is true and visible is true) as string
    click menu item "Lock Screen" of menu 1 of menu bar item "Apple" of menu bar 1 of application process appName
end tell

      Hint: Mouse over and horizontal/vertical scroll to see full code.

However, the first mentioned solution is more direct.

Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

You can use:

tell application "System Events" to keystroke "q" using {control down, command down}