-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptingCaffeination.swift
More file actions
36 lines (29 loc) · 1.24 KB
/
ScriptingCaffeination.swift
File metadata and controls
36 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// ScriptingCaffeination.swift
// Caffeinator
//
// Created by aaplmath on 7/25/20.
// Copyright © 2020 aaplmath. All rights reserved.
//
import Cocoa
/// A class that exposes a subset of `Caffeination` to OSA. Importantly, this class is compatible with Objective-C and plays well with the archaic technologies involved in scripting. For convenience, all field names match the property names in the sdef file to which they correspond.
@objcMembers class ScriptingCaffeination: NSObject {
static let shared = ScriptingCaffeination()
override private init() {}
override var objectSpecifier: NSScriptObjectSpecifier {
let appDescription = NSApplication.shared.classDescription as! NSScriptClassDescription
print(appDescription)
let specifier = NSPropertySpecifier(containerClassDescription: appDescription, containerSpecifier: nil, key: "caffeination")
return specifier
}
var active: Bool {
get {
return (NSApplication.shared.delegate as! AppDelegate).caffeination.isActive
}
}
var options: [String] {
get {
return (NSApplication.shared.delegate as! AppDelegate).caffeination.opts.map { String(describing: $0) }
}
}
}