Skip to main content
Question

Sleep but not Logout

  • August 8, 2018
  • 5 replies
  • 7 views

Forum|alt.badge.img+4

Hello,

Does anybody have a solution to have the machine fall asleep whilst not logging out of the currently logged in user?

5 replies

mark_mahabir
Forum|alt.badge.img+15
  • Jamf Heroes
  • August 8, 2018

Are your Macs encrypted with FileVault 2?


Forum|alt.badge.img+19
  • Contributor
  • August 8, 2018
#!/bin/bash
loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
sudo -u "$loggedInUser" osascript -e 'tell app "System Events" to sleep'

Forum|alt.badge.img+17
  • Valued Contributor
  • August 8, 2018
pmset sleepnow

Forum|alt.badge.img+4
  • Author
  • Contributor
  • August 8, 2018

@ryan.ball Hey Ryan, I gave your script a shot, seems as though it does put the computer to sleep, but still logs the user off at the same time. Any suggestions?


Forum|alt.badge.img+19
  • Contributor
  • August 8, 2018

@Gennaro Is it logging the user out, or is your "Security & Privacy" preference pane in System Preferences set to "Require password immediately after sleep or screen saver begins"?