Skip to content

Instantly share code, notes, and snippets.

@jormungand
Last active August 12, 2020 03:49
Show Gist options
  • Save jormungand/5dc331551f3c34346509eb36b27012e6 to your computer and use it in GitHub Desktop.
Save jormungand/5dc331551f3c34346509eb36b27012e6 to your computer and use it in GitHub Desktop.
wrapper to build small utility which locks macOS screen from command line
#!/bin/bash
##
## usage: bash -c "$( curl -fsSL https://gist.githubusercontent.com/jormungand/5dc331551f3c34346509eb36b27012e6/raw/ )"
##
## credits: http://apple.stackexchange.com/a/123738, https://stackoverflow.com/a/26492632
##
_tmpdir="$( mktemp -d )"
echo 'extern void SACLockScreenImmediate();
int main()
{
SACLockScreenImmediate();
return 0;
}
' > ${_tmpdir}/main.c
clang -F /System/Library/PrivateFrameworks -framework login -o lockscreen ${_tmpdir}/main.c
rm -rf ${_tmpdir}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment