Is there a simple way to get either (a) when the current user has logged into OSX, or (b) what time did the current user log In? I’m trying to create a simple duration timer for my child. It will keep a running daily tally of how long they’ve been logged in (using the Mac).
Thanks!
using the SHELL command “LAST” will provide who logged on, shutdown etc… just write a Xojo app to execute that command and parse the results …
To take Dave’s suggestion one step further:
theShell.Execute "last | grep `whoami` | head -1"
(those are back-ticks, not apostrophes around whoami)
This will return something like this:
tjones ttys000 Mon Jan 21 08:22 still logged in
Of course you are going to go back more than that last “single” record… as YOU have to be logged on to find out who was on before
when I just typed in LAST it showed all the way back to Nov6, but then I last rebooted this computer on Dec 20th at 4:18pm
TC asked about the “current” user. That’s what my head -1 provides.
Thanks everyone!
I actually had good luck for my needs by doing this:
Dim s As Shell
s = New Shell
s.Execute("pmset -g log | grep 'Display is turned o'")
Then parsing out the “on” vs “off” and doing a bit of date adding and subtracting…
@TC Conway You also might be interested in ‘ac’ command (connect-time accounting). It can give you a list of the time spent connected per user and/or per day