I have a perl script (this script, to be exact) that logs user activity based on idle time on a MacOS X Snow Leopard System. However, with Fast User Switching enabled, more than one user might be logged in at the same time. I want the script to see the computer as 'idle' if another user is active (i.e. using the GUI) through Fast User Switching.
There are numerous ways to figure out when a user logged in. Finding out when a user last "switched" seems more difficult. My solution so far was to look at
/var/log/secure.log, where Fast User Switching events are logged:
tail -200 /var/log/secure.log | grep "User info context values set" | tail -1
However, for users running the perl script that are not Admin,
secure.log will not be readable. Are there any alternative ways to find out which user is currently actively logged in, or what the last Fast User Switching event was?
Of course, the problem could be circumvented if I had a method for finding out the idle time for the user running the script only, not the total idle time of the computer I'm currently getting from
ioreg. So, I'm open to suggestions there as well.