This guide walks you through the installation, configuration, execution, and validation of the automatic Mac lock system based on iPhone Bluetooth proximity.
- autolockscript.sh – The shell script that checks your iPhone's RSSI and locks the screen.
- com.iphone.lock.plist – LaunchAgent to make the script run automatically.
- uninstall.sh – Script to cleanly remove everything.
- Move the script to a permanent location:
mkdir -p ~/bin
mv ~/Downloads/autolockscript.sh ~/bin/
chmod +x ~/bin/autolockscript.sh- Edit the script and configure iPhone name:
Open
autolockscript.shin a text editor and replace:
IPHONE_NAME="Your iPhone Name Here"With your actual iPhone name as listed in: System Settings > Bluetooth
- Copy the LaunchAgent file:
cp ~/Downloads/com.iphone.lock.plist ~/Library/LaunchAgents/Make sure it points to your script path, e.g., /Users/YOUR_USERNAME/bin/autolockscript.sh
- Load the LaunchAgent:
launchctl load ~/Library/LaunchAgents/com.iphone.lock.plist- Check that it's running:
launchctl list | grep com.iphone.lockIf you see a numeric PID (process ID), the service is active.
To monitor the script activity:
tail -f /tmp/iphone-lock-monitor.logYou will see RSSI readings every few seconds. If the iPhone moves out of range and the RSSI drops below -65, it will trigger:
RSSI too low. Locking screen...
To manually test locking, run:
/usr/bin/pmset displaysleepnow- Run the uninstall script:
bash ~/Downloads/uninstall.sh- Alternatively, do it manually:
launchctl unload ~/Library/LaunchAgents/com.iphone.lock.plist
rm ~/Library/LaunchAgents/com.iphone.lock.plist
rm ~/bin/autolockscript.sh
rm /tmp/iphone-lock-monitor.log
rm /tmp/iphone-lock-launchd.out
rm /tmp/iphone-lock-launchd.err- Make sure Bluetooth is enabled and the iPhone is paired at least once.
- In System Settings > Lock Screen, set: "Require password after sleep or screen saver" → Immediately.
- The script adapts scanning frequency: normal every 10s, more frequent (1s) during RSSI drops.
This project is portable, secure, and customizable. Suitable for developers and privacy-conscious users who want their Mac to react to physical presence.