Is a machine being used right now? - BlueSkyTools/BlueSkyConnect GitHub Wiki

Sometimes if you want to do work on a remote machine, you want to do it outside the office hours to not interfere with the user. This Command shows you if a user is logged in and for how long the machine is idle. It's working quite well for me to decide if someone is logged in or not:

clear && idle_time=$(/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'); if [ "$(osascript -l JavaScript -e 'ObjC.import("CoreGraphics"); $.CGDisplayIsActive($.CGMainDisplayID())')" == "1" ](/BlueSkyTools/BlueSkyConnect/wiki/-"$(osascript--l-JavaScript--e-'ObjC.import("CoreGraphics");-$.CGDisplayIsActive($.CGMainDisplayID())')"-==-"1"-); then echo "‼️unlocked and idle for $(echo $idle_time | awk '{printf "%dm %ds", $1/60, $1%60}')"; else echo "✅ locked and idle since $(echo $idle_time | awk '{printf "%dm %ds", $1/60, $1%60}')"; fi

It looks like this:

‼️unlocked and idle for 0m 0s

or:

✅ locked and idle since 18m 52s