Sunday, November 27, 2022

#1 2022-02-23 10:37:06 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 89
Website

Seeking documentation on NSScreen

I have an applet which I need to be useable in all versions of macOS from 10.10 onwards.  In the applet I have this code for getting the screen's dimensions:

Applescript:

set mainScreenFrame to current application's NSScreen's mainScreen()'s frame() as list
set screen_width to item 1 of item 2 of mainScreenFrame as integer
set screen_height to item 2 of item 2 of mainScreenFrame as integer

In macOS 10.13 and above, the mainScreenFrame variable has contents that look like this:

0.0, 0.0, 2560.0, 1440.0


But, in OS X 10.11, mainScreenFrame contains this:

x:0.0, y:0.0, width:2560.0, height:1415.0

Which naturally causes an error in the next line of code which tries to get screen_width.

It seems that different data is returned by NSScreen's mainScreen()'s frame() in different versions of macOS. I can't find any documentation on this.  I've Googled and searched Apple's documentation but can't find anything on this.

Does anyone know where to find such documentation ?

Thanks.

Model: iMac (Retina 5K, 27-inch, Late 2015)
Browser: Safari 15.3 (17612.4.9.1.8)
Operating System: macOS 12


Public servants are people too
Mac Studio M1 Max 24c, 32GB, 1TB; Studio Display; macOS Monterey, 12.3.1

Offline

 

#2 2022-02-24 12:56:12 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6797

Re: Seeking documentation on NSScreen

It changed in High Sierra. You can read about workarounds here:

https://latenightsw.com/high-sierra-app … objc-bugs/


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2022-02-24 10:40:54 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 89
Website

Re: Seeking documentation on NSScreen

Shane Stanley wrote:

It changed in High Sierra. You can read about workarounds here:
https://latenightsw.com/high-sierra-app … objc-bugs/


Many thanks. No wonder I couldn't find mention in Apple's documentation.  Before looking at the suggestion, my code was designed for 10.13+.  So, I decided to work around by adding code specifically for 10.11 and 10.12. It works but not as compact.

Cheers.


Public servants are people too
Mac Studio M1 Max 24c, 32GB, 1TB; Studio Display; macOS Monterey, 12.3.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)