How long OS user is logged in

  1. 3 weeks ago

    TC C

    Jan 22 Washington, DC

    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!

    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
  2. Dave S

    Jan 22 San Diego, California USA

    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 .....

  3. Tim J

    Jan 22 Pre-Release Testers, Xojo Pro Answer Dehydrating in AZ

    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
  4. Dave S

    Jan 22 San Diego, California USA
    Edited 3 weeks ago

    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 :)

  5. Tim J

    Jan 22 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    TC asked about the "current" user. That's what my head -1 provides. :)

  6. TC C

    Jan 24 Washington, DC

    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..

  7. @TC C — 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

or Sign Up to reply!