|# When you are working on your macbook sitting in cafe and you have to go pee,|
|# you need some way to guard you machine.|
|# Start this script, remove any earphones, and go do the job.|
|# The assumption is the thief will close the lid of the laptop before taking it away.|
|# This script detects the closing of the lid and plays some loud audio that will|
|# likely distract the thief and/or grab attention of nearby people, making the|
|# thief abondon his/her attempt of larceny|
|if [[ ! -f `which NoSleepCtrl` ]]|
|echo "Please install NoSleepCtrl from "|
|echo " https://github.com/integralpro/nosleep/releases"|
|echo " "|
|echo "Install it with CLI included in it. It's necessary to prevent"|
|echo "your macbook from going to sleep when somebody closes the clamshell."|
|echo "When you launch this script it will automatically turn the 'NoSleep'"|
|echo "mode ON and when you exit the script with Ctrl-C, the 'NoSleep' mode"|
|echo "will automatically be turned OFF."|
|echo "(You are not required to be running it in the tray)"|
|echo " "|
|NoSleepCtrl -a -s 1|
|NoSleepCtrl -b -s 1|
|NoSleepCtrl -a -s 0|
|NoSleepCtrl -b -s 0|
|# Reset the volume to medium value|
|osascript -e "set Volume 5"|
|# Turn Volume Up all the way|
|osascript -e "set Volume 10"|
|trap onCtrlC SIGINT|
|CLAMSHELL_OPEN=`ioreg -r -k AppleClamshellState -d 4 | \|
|grep AppleClamshellState | \|
|head -1 | cut -d = -f 2`|
|if [ $CLAMSHELL_OPEN == "Yes" ] || [ $INTRUSION_DETECTED -eq 1 ]|
|say -v Fiona "Please stay away from this laptop"|
|say -v Fiona "This machine will auto destruct in"|
|while [ $count -gt 0 ]|
|say -v Fiona "$count"|
|for i in `seq 1 $LAUGHTER_LENGTH`|
|say -v "Hysterical" "Ha Ha Ha"|
Mar 30, 2016
osascript -e "set Volume 10"
needs to happen after an Intrusion was detected, otherwise, simply pressing mute defeats this mechanism.
Otherwise, awesome script.
Mar 31, 2016
I know this is probably just for fun, and I hate to be that guy to make a serious comment and ruin the joke, but if anyone's serious about using this as intended...
If I wanted the data on your Macbook, I would NOT close the lid, because I'd want to avoid locking the current session. I'd probably lower the lid somewhat, but short of closing it all the way, so maybe you could use the light sensor instead? In fact, no one should be touching the thing at all while you're gone, so you could also maybe use the accelerometer to detect the laptop being picked up. A combination of all three of these things (I'm not sure if light sensor and accelerometer are exposed via API) should be pretty solid!
Apr 1, 2016
@Sawaba excellent suggestion about accelerometer input. On some investigation I found it's called 'Sudden Motion Sensor' and apparently there's a CLI utility for that. I'll give it a try when I get chance.