Add currentGUIUsers() function

This commit is contained in:
Greg Neagle
2024-09-04 13:42:35 -07:00
parent 3479598448
commit 58937254b1
3 changed files with 31 additions and 0 deletions
@@ -0,0 +1,8 @@
//
// SignalHandler.swift
// munki
//
// Created by Greg Neagle on 9/4/24.
//
import Foundation
@@ -0,0 +1,8 @@
//
// UNIXProcessInfo.swift
// munki
//
// Created by Greg Neagle on 9/4/24.
//
import Foundation
+15
View File
@@ -36,6 +36,21 @@ func getConsoleUser() -> String {
return SCDynamicStoreCopyConsoleUser(nil, nil, nil) as? String ?? ""
}
func currentGUIUsers() -> [String] {
// Gets a list of GUI users by parsing the output of /usr/bin/who
var guiUsers = [String]()
let result = runCLI("/usr/bin/who")
for line in result.output.components(separatedBy: .newlines) {
let parts = line.components(separatedBy: .whitespaces).filter {
!$0.isEmpty
}
if parts.count > 1, parts[1] == "console" {
guiUsers.append(parts[0])
}
}
return guiUsers
}
func getIdleSeconds() -> Int {
// Returns the number of seconds since the last mouse
// or keyboard event.