-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmacism.swift
More file actions
51 lines (43 loc) · 1.48 KB
/
macism.swift
File metadata and controls
51 lines (43 loc) · 1.48 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Foundation
@main
struct MacISM {
static func main() {
if CommandLine.arguments.contains(where: { arg in
arg.caseInsensitiveCompare("--version") == .orderedSame
}) {
print("v3.0.10")
return
}
// Initialize input sources
InputSourceManager.initialize()
if CommandLine.arguments.count == 1 {
let currentSource = InputSourceManager.getCurrentSource()
print(currentSource.id)
} else {
// Process command line arguments for flags
let arguments = CommandLine.arguments
// Filter out flag arguments to get the input source name
let filteredArgs = arguments.filter { arg in
!arg.hasPrefix("--")
}
if filteredArgs.count < 2 {
print("No input source name provided!")
return
}
guard let dstSource = InputSourceManager.getInputSource(
name: filteredArgs[1]
) else {
print("Input source \(filteredArgs[1]) does not exist!")
return
}
// Set wait time if provided
if filteredArgs.count == 3, let waitTime = Int(filteredArgs[2]) {
// ignore waitTime of none-zero
if waitTime == 0 {
InputSourceManager.waitTimeMs = waitTime
}
}
dstSource.select()
}
}
}