Get the Windows Heights

In OS 10.12 we were able to get the windows heights and change it with this handler.

on reduceWindowHeight_(sender)
		set theFrame to (lighterItemsWindow's frame()) as record
		if ((height of |size| of theFrame) as integer) = 577 then -- Reduce only if the window is a certain size
			set y of origin of theFrame to ((y of origin of theFrame) as integer) + 200
			set height of |size| of theFrame to (((height of |size| of theFrame) as integer) - 200)
			tell lighterItemsWindow to setFrame_display_animate_(theFrame, true, true)
		end if
	end reduceWindowHeight_

and would have returned a record like this.
[format]
{
origin = {
x = 899;
y = 598;
};
size = {
height = 377;
width = 655;
};
}
[/format]

In OS 10.13 this line of code doesn’t return a record anymore but, a list. Will error if “as record” not commented out.


set theFrame to (lighterItemsWindow's frame()) --as record

[format] (
899,
598
),
(
655,
377
)[/format]

How can we grab the origin and size like we use to???
[format]
@property(readonly) NSRect frame;
typedef CGRect NSRect;
[/format]

You can read about what’s happening and how to work around it here:

http://latenightsw.com/high-sierra-applescriptobjc-bugs/

I don’t know much objective c but could you just coerce it to a record manually


set windowFrame to frameToRecord()
reduceWindowHeight(windowFrame, 100) -- drops height by 100 px

      on frameToRecord()
		set theFrame to windowMain's frame as list
		set AppleScript's text item delimiters to ","
		set x to text item 1 of (item 1 of theFrame)
		set y to text item 2 of (item 1 of theFrame)
		set width to text item 1 of (item 2 of theFrame)
		set height to text item 2 of (item 2 of theFrame)
		set AppleScript's text item delimiters to ""
		
		return {xOrigin:x, yOrigin:y, width:width, height:height} --returns the data as a record, ready for manipulation
	end frameToRecord
	
	
	on reduceWindowHeight(input, reduction)
		set (input's height) to ((input's height) - reduction)
	end reduceWindowHeight



As of Mac OS 10.13.2 the bug has still not been fixed so I’ll just test to see what class is returned.


on reduceWindowHeight_(sender)
        
    set theFrame to (lighterItemsWindow's frame()) --as record
     -- Need to find returned class due to bug in 10.13 OS
    if class of theFrame is list then
            set {{theX, theY}, {theWidth, theHeight}} to theFrame
            if (theHeight as integer) = 577 then
                set theY to ((theY as integer) + 200)
                set theHeight to ((theHeight as integer) - 200)
                tell lighterItemsWindow to setFrame_display_animate_ ({{theX, theY}, {theWidth, theHeight}}, true, true)
            end if
    else
		
		if ((height of |size| of theFrame) as integer) = 577 then -- Reduce only if the window is a certain size
			set y of origin of theFrame to ((y of origin of theFrame) as integer) + 200
			set height of |size| of theFrame to (((height of |size| of theFrame) as integer) - 200)
			tell lighterItemsWindow to setFrame_display_animate_(theFrame, true, true)
		end if
    end if
	end reduceWindowHeight_