Automatically locks or unlocks the screen based on proximity to trusted devices (Wi-Fi, Bluetooth).
fisher install edouard-lopez/smart-lock.fish💡 Requirements
- icons-in-terminal for gray icons support (optional) ;
- Fisher - Fish plugin manager
xprintidle- X11 idle time detectionnmcli- NetworkManager CLI for Wi-Fi detection (vianetwork-manager)bluetoothctl- Bluetooth device detection (viabluezpackage)cinnamon-screensaver-command(or modify for your DE)xset: to manage display power
For Debian/Ubuntu-based systems:
apt install network-manager bluez xprintidle x11-xserver-utils cinnamon-screensaver
What to do after installation:
- Configure the trusted devices and idle timeout variables ;
- Run
smart_lock_toggleperiodically (e.g., via cron or systemd timer) ; - Display the lock status in your prompt.
Set environment variables to define trusted devices and idle timeout.
| Variable | Default | Description |
|---|---|---|
SMART_LOCK_BSSIDS |
- | List of trusted Wi-Fi BSSIDs as MAC addresses e.g. home Wi-Fi, office Wi-Fi |
SMART_LOCK_DEVICES_MACS |
- | List of trusted Bluetooth as MAC addresses e.g. smartphone, mouse) |
SMART_LOCK_AFTER |
180 |
Idle timeout in seconds |
Example configuration in config.fish:
set --universal SMART_LOCK_BSSIDS "AA:BB:CC:DD:EE:FF" "BB:CC:DD:EE:FF:AA"
set --universal SMART_LOCK_DEVICES_MACS "CC:DD:EE:FF:AA:BB"
set --universal SMART_LOCK_AFTER 300You need to run smart_lock_toggle periodically to check the proximity of trusted devices to update SMART_LOCK_STATUS and trigger screen lock and unlock the screen accordingly.
Systemd handles environment variables and logging better than cron.
mkdir -p ~/.config/systemd/user/[Unit]
Description=Smart Lock Toggle Service
[Service]
Type=oneshot
ExecStart=/usr/bin/fish -c 'source $__fish_config_dir/functions/smart_lock_toggle.fish && smart_lock_toggle'[Unit]
Description=Smart Lock Toggle Timer
[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
Unit=smart-lock.service
[Install]
WantedBy=timers.targetsystemctl --user enable --now smart-lock.timerIf you prefer cron, use the following.
ℹ️ Note that you may need to set
DISPLAYandDBUS_SESSION_BUS_ADDRESSmanually if they are not picked up.
# give some context to cron jobs
DISPLAY=:0
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
# run every minute
* * * * * fish -c 'source $__fish_config_dir/functions/smart_lock_toggle.fish && smart_lock_toggle'You can always run it manually
smart_lock_toggleAdd the following to your prompt to show lock status:
echo $SMART_LOCK_STATUSℹ️ If you didn't customize your fish_right_prompt.fish, you can use our
Install our fish_right_prompt
Backup existing fish_right_prompt.fish
cp $__fish_config_dir/functions/{,__backup_}fish_right_prompt.fishReplace with smart_lock version
cp $__fish_config_dir/functions/{__smart_lock_,}fish_right_prompt.fish