Created
June 23, 2022 22:08
-
-
Save chilcote/5d53239ae485c20418e4027fa365619d to your computer and use it in GitHub Desktop.
Use this to list out all the launchd plists in LaunchDaemons and LaunchAgents, and report the SMAppService.statusForLegacyPlist status.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import ServiceManagement | |
func printStatus(plistPath: String) -> String { | |
let plistURL = URL(fileURLWithPath: plistPath) | |
let status = SMAppService.statusForLegacyPlist(at: plistURL) | |
switch status { | |
case .notRegistered: | |
return plistPath + " is not registered" | |
case .enabled: | |
return plistPath + " is enabled" | |
case .requiresApproval: | |
return plistPath + " is requires approval" | |
case .notFound: | |
return plistPath + " is not found" | |
@unknown default: | |
return plistPath + " is unknown" | |
} | |
} | |
let localFileManager = FileManager() | |
let daemonsDir = "/Library/LaunchDaemons" | |
let daemonsEnum = localFileManager.enumerator(atPath: daemonsDir) | |
let agentsDir = "/Library/LaunchAgents" | |
let agentsEnum = localFileManager.enumerator(atPath: agentsDir) | |
print("LaunchDaemons:") | |
while let file = daemonsEnum?.nextObject() as? String { | |
if file.hasSuffix(".plist") { | |
// print(daemonsDir.appending("/\(file)")) | |
let status = printStatus(plistPath: daemonsDir.appending("/\(file)")) | |
print(status) | |
} | |
} | |
print("LaunchAgents:") | |
while let file = agentsEnum?.nextObject() as? String { | |
if file.hasSuffix(".plist") { | |
// print(agentsDir.appending("/\(file)")) | |
let status = printStatus(plistPath: agentsDir.appending("/\(file)")) | |
print(status) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment