-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonIdleTimer.sh
More file actions
42 lines (31 loc) · 1.18 KB
/
PythonIdleTimer.sh
File metadata and controls
42 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
###########################################################################################
#
# IdleTimer written by KClose.
# Last updated: April 2, 2020
#
# IdleTimer leverages Python and Quartz to get the actual idle time of a computer.
# Unlike the BASH altternative, this function works regardless of local or remote activity.
# Results will be acurate to +- 5 seconds as it takes a second for Python to run.
#
###########################################################################################
echo "Getting idle time from Python."
# Use Python to get the actual idle time.
# Define the IdleTime variable by running an embedded Python script (EOF - EOF)
IdleTime=$(python - << EOF
# Importing necessary functions from Quarts CoreGraphics and SystemEvents
from Quartz.CoreGraphics import *
NX_ALLEVENTS = int(4294967295) # 32-bits, all on.
# Build the function to get actual Idle Time
def getIdleTime():
"""Get number of seconds since last user input"""
idle = CGEventSourceSecondsSinceLastEventType(1, NX_ALLEVENTS)
return idle
# Run Idletime Function
idle = getIdleTime()
# Return idle time
print(idle)
EOF
)
echo "IdleTimer Returned " $IdleTime
exit 0