liamhp needs to attract extra consideration to this query.
I am constructing a flutter app and screen-size testing through working a MacOS construct and resizing the window through Shortcuts x AppleScript. Here is the method:
Manually enter show screen-size (in my case 13.3in for Macbook Air 2019) – if you realize a approach to automate this with AppleScript please lmk
set diagonalSizeInInches to 13.3
Mechanically fetch show size and width (in px)
inform software “Finder”
set screenBounds to bounds of window of desktop
finish inform
set displayW to merchandise 3 of screenBounds
set displayH to merchandise 4 of screenBounds
Compute show PPI
set equation to (displayW as string) & “^2 + ” & (displayH as string) & “^2”
set diagonalResolution to do shell script “echo ‘sqrt(” & equation & “)’ | bc -l”
set displayPPI to diagonalResolution / diagonalSizeInInches
Immediate the person to pick out a check system from the listing
— outline check units as: mannequin, width (px), peak (px), ppi
set iPhoneSizes to {¬
{“iPhone 13 Professional”, 2532, 1170, 460}}
set modelNames to {}
repeat with thisModel in iPhoneSizes
set finish of modelNames to merchandise 1 of thisModel
finish repeat
set selectedModel to (select from listing modelNames with immediate “Choose an iPhone mannequin:” default gadgets {“”})
if selectedModel is fake then
show dialog “No mannequin chosen. Exiting script.”
return
finish if
Compute the right window measurement primarily based on the chosen system
set screenW to 0
set screenH to 0
set selectedModelName to merchandise 1 of selectedModel
repeat with thisModel in iPhoneSizes
if merchandise 1 of thisModel is the same as selectedModelName then
set screenH to (merchandise 2 of thisModel) * displayPPI / (merchandise 4 of thisModel)
set screenW to (merchandise 3 of thisModel) * displayPPI / (merchandise 4 of thisModel)
exit repeat
finish if
finish repeat
Resize and middle the window
inform software “System Occasions”
inform (first course of whose frontmost is true)
if (rely home windows) > 0 then
set win to entrance window
set measurement of win to {screenW, screenH}
set newPosition to {(displayW – screenW) / 2, 2}
set place of win to newPosition
else
show dialog “No home windows discovered within the frontmost software.”
finish if
finish inform
finish inform
This works… largely. Nonetheless, for some purpose the display screen sizes aren’t precisely the identical. When you’ve got perception on what is going on mistaken right here, please lmk- my guess is that it has one thing to do with inexact dimensions from Apple on both my Mac show or the Cellphone itself, however possibly I simply missed one thing in my calculations? That is my first time utilizing AppleScript so when you’ve got another enhancements on that code, I might like to see them.
On my bodily system (Iphone 13 Professional):
MediaQuery.of(context).measurement.width: 390.0
MediaQuery.of(context).measurement.peak: 844.0
On the put in IOS Simulator (Iphone 13 Professional):
MediaQuery.of(context).measurement.width: 390.0
MediaQuery.of(context).measurement.peak: 844.0
On the window-resized macOS construct (at 13.3in 1440x900px show, 2532x1170px 460ppi simulated system):
MediaQuery.of(context).measurement.width: 325.0
MediaQuery.of(context).measurement.peak: 675.0