Python pyatom: setting window size and position

172 views Asked by At

I've got a window that always loads up in my app at position x=780.0, y=222.0

I've been trying lots of different ways to change the window size and position however when I use component.setString("AXPosition", {0,0}) I keep getting the following error: atomacos.errors.AXErrorFailure: There is some sort of system memory failure.

I must be doing something wrong but any advice would be appreciated.

If I use component.AXPosition = {0,0} I get no errors but the position has still not changed, however if I use component.AXPosition = 0 or any number at all it always sets the position to x=0.0 y=1327.0 (the bottom left corner of my screen). ???

I've even tried a similar method to _converter.py in the repo but it still raises AXErrorFailure:

CGPoint=namedtuple("CGPoint", ("x", "y"))
from ApplicationServices import NSPointFromString
point = NSPointFromString("{x: 0, y: 0}")
component.AXPosition = CGPoint(point.x, point.y)
1

There are 1 answers

0
harveyf2801 On BEST ANSWER

After a bit of digging, for those with a similar issue setting window sizes / positions this is the code:

    from ApplicationServices import AXValueCreate, kAXValueCGPointType
    import Quartz.CoreGraphics as CG

    x, y = 200, 300
    point = CG.CGPoint(x=x, y=y)
    component.AXPosition = AXValueCreate(kAXValueCGPointType, point)