This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CoreScripts.swift
67 lines (59 loc) · 2.42 KB
/
CoreScripts.swift
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// CoreSound.swift
// Radio Automne
//
// Created by Aydar Nasibullin on 02.10.2020.
// Copyright © 2020-2021 Fetch Development. All rights reserved.
//
import Foundation
import AudioToolbox
import Cocoa
class AutomneCore {
private static let volurl = Bundle.main.url(forResource: "GetVolume", withExtension: "scpt")
private static var volerror: NSDictionary?
private static let volscriptObject = NSAppleScript(contentsOf: volurl!, error: &volerror)
private static let slurl = Bundle.main.url(forResource: "SystemSleep", withExtension: "scpt")
private static var slerror: NSDictionary?
private static let slscriptObject = NSAppleScript(contentsOf: slurl!, error: &slerror)
private static let churl = Bundle.main.url(forResource: "SystemSleepCheck", withExtension: "scpt")
private static var cherror: NSDictionary?
private static let chscriptObject = NSAppleScript(contentsOf: churl!, error: &cherror)
public static func getSystemVolume() -> Int{
if let outputString = volscriptObject?.executeAndReturnError(&volerror).stringValue {
return Int(outputString) ?? -1
} else if (volerror != nil) {
print("ERROR8: ", volerror!)
return -1
}
return -1
}
public static func systemSleep(){
if (slscriptObject?.executeAndReturnError(&slerror).stringValue) != nil {
} else if (slerror != nil) {
print("ERROR9: " + slerror!.description)
}
}
public static func systemSleepCheck(){
if (chscriptObject?.executeAndReturnError(&cherror).stringValue) != nil {
} else if (cherror != nil) {
print("ERROR9: " + cherror!.description)
}
}
public static func notify(title: String, subtitle: String = ""){
if !NSApplication.shared.isActive{
let notification = NSUserNotification()
notification.hasActionButton = false
notification.setValue(true, forKey: "_ignoresDoNotDisturb")
notification.title = title
notification.informativeText = subtitle
NSUserNotificationCenter.default.deliver(notification)
}
}
public static func displayAlert(title: String, message: String){
let alert = NSAlert()
alert.messageText = title
alert.informativeText = message
alert.addButton(withTitle: "OK")
alert.runModal()
}
}