Reputation: 5742
In my Mac app i am trying to lock my Mac based on some actions in my app. Until now i have only got a way to put it to sleep but not lock. Currently i am doing this :
let appleScript = NSAppleScript(source: "tell application \"Finder\" to sleep")
appleScript?.executeAndReturnError(nil)
Please guide.
Upvotes: 0
Views: 320
Reputation: 1171
Instead of
tell application "Finder" to sleep
Use the following:
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
You will need to escape the " characters with \ as you have already with the Finder command.
Upvotes: 1