Hello, love the app,
I configured an automation that locks my mac when it detects movement away from the computer. Then I discovered that with web server enabled my btt named trigger works even when my mac is sleeping, which results in the computer also waking up as I get near my desk...
That got old pretty quickly though,
and I wondered if I could change the behaviour based on wether the screen is locked. Sadly couldn't find that condition.
It might be useful considering most of the time the computer is sleeping 
Apparently it can be checked using the
ioreg -n Root -d1 | grep -i "CGSSessionScreenIsLocked"
terminal command.
I guess the more universal/advanced way could be to allow to check terminal output of a custom command as a general "do custom stuff" condition.
I'd appreciate any help in this matter! 
MM
Hi there,
I have implemented similar...(when my Apple Watch is not "close" to my Mac anymore then BTT lock my screen), but only when the screen is not locked...
a "Repeating or Time Based Trigger" is used (runs every 30sec) :
The screen lock state is checked with the first script and a BTT var is created. That var is then checked ( IF ) whether the Apple Watch is in reach (second script)...
#!/bin/bash
IS_LOCKED=$(ioreg -n Root | grep -i "CGSSessionScreenIsLocked" | grep "Yes")
if [ "$IS_LOCKED" != "" ]; then
# Setze BTT-Variable auf "locked"
osascript -e 'tell application "BetterTouchTool" to set_string_variable "screen_state" to "locked"'
else
# Setze BTT-Variable auf "unlocked"
osascript -e 'tell application "BetterTouchTool" to set_string_variable "screen_state" to "unlocked"'
fi
.
.
the second script locks the screen based on a RSSI threshold...and has a logging mode: writes a file ( ~/btt_data/btt_rssi_log.txt ) to debug RSSI.
target_mac address is that from the Apple Watch
set mode to off to disable logfile...
Important adjust those, if needed
THRESHOLD=-75
LOGFILE=~/btt_data/btt_rssi_log.txt
TARGET_MAC="AA:BB:CC:DD:EE:FF"
MODE="on" # logging "on" oder "off"
#!/bin/bash
THRESHOLD=-75
LOGFILE=~/btt_data/btt_rssi_log.txt
TARGET_MAC="AA:BB:CC:DD:EE:FF"
MODE="on" # logging "on" oder "off"
log() {
if [ "$MODE" == "on" ]; then
echo "$1" >> "$LOGFILE"
fi
}
log "========== $(date '+%Y-%m-%d %H:%M:%S') =========="
log "π Apple Watch RSSI bluetooth logging modus: $MODE"
# Bluetooth-Daten holen
BLOCK=$(system_profiler SPBluetoothDataType | awk -v mac="$TARGET_MAC" "/$TARGET_MAC/,/^$/" | head -n 2)
log "π¦ Bluetooth-Block fΓΌr $TARGET_MAC:"
log "$BLOCK"
# RSSI extrahieren
RSSI=$(echo "$BLOCK" | grep "RSSI" | awk '{print $2}')
if [ -z "$RSSI" ]; then
log "β οΈ Kein RSSI β Mac wird gesperrt"
osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}'
exit 0
fi
log "πΆ RSSI: $RSSI | Schwelle: $THRESHOLD"
if [ "$RSSI" -lt "$THRESHOLD" ]; then
log "π RSSI < Schwelle β Mac wird gesperrt"
osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}'
else
log "β
Kein Sperren nΓΆtig"
fi
Mac 15.5 BTT 5.540
have fun,
Christian
1 Like
Just another note:
You can always use the "IF Java Script Returns True" condition if you want to check the output of scripts etc.:
1 Like