mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
33 lines
836 B
Swift
33 lines
836 B
Swift
//
|
|
// launchAtLogin.swift
|
|
// StatsKit
|
|
//
|
|
// Created by Serhiy Mytrovtsiy on 14/04/2020.
|
|
// Using Swift 5.0.
|
|
// Running on macOS 10.15.
|
|
//
|
|
// Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
import ServiceManagement
|
|
|
|
public struct LaunchAtLogin {
|
|
private static let id = "\(Bundle.main.bundleIdentifier!).LaunchAtLogin"
|
|
|
|
public static var isEnabled: Bool {
|
|
get {
|
|
guard let jobs = (SMCopyAllJobDictionaries(kSMDomainUserLaunchd).takeRetainedValue() as? [[String: AnyObject]]) else {
|
|
return false
|
|
}
|
|
|
|
let job = jobs.first { $0["Label"] as! String == id }
|
|
|
|
return job?["OnDemand"] as? Bool ?? false
|
|
}
|
|
set {
|
|
SMLoginItemSetEnabled(id as CFString, newValue)
|
|
}
|
|
}
|
|
}
|