Last active
March 29, 2022 21:22
-
-
Save tmandry/e88ca15045cd02a97fa1034edf90ba98 to your computer and use it in GitHub Desktop.
Getting Spaces and their order for each display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var observer: Observer! | |
func stuff() { | |
guard let database = UserDefaults.init(suiteName: "com.apple.spaces") else { | |
fatalError("cannot read spaces data") | |
} | |
print(String(describing: database.object(forKey: "SpacesDisplayConfiguration"))) | |
observer = Observer(object: database) | |
} | |
class Observer: NSObject { | |
@objc var database: UserDefaults | |
var observation: NSKeyValueObservation? | |
init(object: UserDefaults) { | |
database = object | |
super.init() | |
database.addObserver(self, forKeyPath: "SpacesDisplayConfiguration", options: [.new, .old, | |
.initial], context: nil); | |
} | |
override func observeValue(forKeyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: | |
Any]?, context: UnsafeMutableRawPointer?) { | |
print("changed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Off the top of my head I don't know, but it seems plausible that it would.
Mostly I've just had to experiment with little programs and find out what happens. (Which isn't great for backwards/forwards compatibility, but not much else you can do.)