User Idle Time Timer Script Not Working Any More with M2

sgiesbrecht
Contributor III

Hello everyone

Need assistance with users idle time.

When I run the following script on my workstation ( Apple M1 Backbook Pro ) I get what I need but when I run on a M2 Mac mini, it does not work.

After moving the mouse or pressing a key, the counter just keep increasing.  It looks like the IOHIDSystem is using the computer logged in time.  

I am wondering is there a new way to check for user idle time, command or in Jamf Pro itself.

See the out below.

 

 

#!/bin/zsh

# Pause/Interval between checks
checkInt=1

# Timer in sec
timerLength=15

# Keep track of the idle timer
lastIdle=0

# Get the current user
current_user=$(who | awk '/console/{print $1}')

# Get the computer name 
computer_name=$(hostname | sed 's/.local//')

# Message to system.log
log_message="User $current_user Test"

# Function
while true ; do
	ioresp=`ioreg -w 0 -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'`
	idleNow=`echo $(( ${ioresp} / 1000000000 ))`

	# Get the current date and time
	current_datetime=$(date "+%Y-%m-%d %H:%M:%S")

	re='^[0-9]+$'
	if ! [[ $idleNow =~ $re ]] ; then
		echo "error: ioreg did not return a number" >&2; exit 1
	fi
	
	echo "Idle now is $idleNow secs"
	
	# if idle decreased then action occurred so we do something...
	if [ $idleNow -ge $timerLength ] ; then
		echo "$log_message at $current_datetime"
		exit 0
	fi
	
	sleep $checkInt
done

 

 

M1 output

 

 

Idle now is 0 secs
Idle now is 1 secs
Idle now is 2 secs
Idle now is 3 secs
Idle now is 4 secs
Idle now is 0 secs <= moved mouse and counter restarted
Idle now is 0 secs
Idle now is 1 secs
Idle now is 2 secs
Idle now is 3 secs
Idle now is 4 secs
Idle now is 5 secs
Idle now is 7 secs
tIdle now is 0 secs <= pressed the letter T and counter restarted
Idle now is 1 secs
Idle now is 2 secs
Idle now is 4 secs
Idle now is 5 secs
Idle now is 6 secs
Idle now is 7 secs
Idle now is 8 secs
Idle now is 9 secs
Idle now is 10 secs
Idle now is 11 secs
Idle now is 12 secs
Idle now is 13 secs
Idle now is 14 secs
Idle now is 15 secs
User sgiesbrecht Test at 2023-08-25 13:29:14 <= Timer reached and performed the command

 

 

On the new M2

 

 

Idle now is 8727 secs
User user Test at 2023-08-25 13:31:24
Idle now is 8728 secs
User user Test at 2023-08-25 13:31:25
Idle now is 8729 secs
User user Test at 2023-08-25 13:31:26 <= moved mouse
Idle now is 8730 secs
User user Test at 2023-08-25 13:31:27
Idle now is 8731 secs
User user Test at 2023-08-25 13:31:28
Idle now is 8732 secs
User user Test at 2023-08-25 13:31:29
Idle now is 8734 secs
User user Test at 2023-08-25 13:31:30 <= pressed letter T
Idle now is 8735 secs
User user Test at 2023-08-25 13:31:32
Idle now is 8736 secs
User user Test at 2023-08-25 13:31:33
Idle now is 8737 secs
User user Test at 2023-08-25 13:31:34
Idle now is 8738 secs
User user Test at 2023-08-25 13:31:35

 

 

 

0 REPLIES 0