tmandry / Swindler

macOS window management library for Swift
https://tmandry.github.io/Swindler/docs/main/
MIT License
695 stars 66 forks source link

Crash on setting frame - AXError.AttributeUnsupported #47

Closed AnthoPakPak closed 5 years ago

AnthoPakPak commented 5 years ago

Hi, I'm discovering your library in order to replace my current code which is currently using ScriptingBridge.

I'm trying to set the frame of the window, with code from SwindlerExample. Here is the code i use :

    Swindler.initialize().then { state -> () in
        self.swindler = state
        self.setupEventHandlers()

        for (index, app) in self.swindler.runningApplications.enumerated() {
            print("App: \(index): \(app)")

            if (app.bundleIdentifier == "com.apple.finder") {
                let finderApp = app;
                print("Desc: \(finderApp.description)")

                let finderWindow = finderApp.knownWindows.first

                finderWindow?.size.set(CGSize(width: 100, height: 100)) //working
                finderWindow?.frame.set(CGRect(origin: CGPoint(x: 100, y: 100), size: CGSize(width: 300, height: 300))) //crashes with invalid attribute error (when debugging, attribute is set to role…)
            }
        }

    }.catch { error in
        print("Fatal error: failed to initialize Swindler: \(error)")
        NSApp.terminate(self)
    }

Am I doing something wrong ? Setting size works correctly. As I want to set the position, I'm using frame (according to the doc), but AXSwift.Attribute is always set to role… Maybe I've made a stupid mistake.

Thanks for your help :)

tmandry commented 5 years ago

Hi, thanks for your report! I've been traveling but finally getting to this now.

This is indeed a bug I introduced in a recent PR. Turns out the frame attribute is not writeable. Working on a fix now.

I'm thinking the role thing is just the debugger reporting the wrong value.