-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClipnotifyMac.swift
32 lines (22 loc) · 866 Bytes
/
ClipnotifyMac.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
// taken from https://github.com/p0deje/Maccy/blob/86b6dd79b2d0f52205bb044c2561175b683a6398/Maccy/Clipboard.swift#L61
import AppKit
class PasteboardWatcher {
private let pasteboard = NSPasteboard.general
private var changeCount : Int
init() {
changeCount = pasteboard.changeCount
}
func startListening () {
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.checkForChangesInPasteboard), userInfo: nil, repeats: true)
}
@objc private func checkForChangesInPasteboard() {
guard pasteboard.changeCount != changeCount else {
return
}
exit(0)
}
}
let pw = PasteboardWatcher()
pw.startListening()
// https://stackoverflow.com/questions/31944011/how-to-prevent-a-command-line-tool-from-exiting-before-asynchronous-operation-co
RunLoop.main.run()