Re: Points vs pixels in a bash script
Re: Points vs pixels in a bash script
- Subject: Re: Points vs pixels in a bash script
- From: Ken Thomases via Cocoa-dev <email@hidden>
- Date: Mon, 8 Jun 2020 17:36:35 -0500
On Jun 8, 2020, at 4:43 PM, Gabriel Zachmann via Cocoa-dev
<email@hidden> wrote:
>
> I have a problem converting points (I think) to pixels in a bash script.
> I'd rather not write an extra C/Cocoa utility for that.
>
> Using
> system_profiler SPDisplaysDataType
> I can retrieve the size of a Mac's display in pixels.
>
> However, the command
>
> tell application "System Events" to get the size of every window of every
> process
>
> (which I execute from my bash script using osascript) apparently does NOT
> return window sizes in pixels. I guess it's the strange "Apple points" units.
> According to my experiments, on my MacBook Pro Retina, for instance, a
> fullscreen app (e.g., Keynote presentation) has a window size of 1680 x 1050.
> By contrast, system_profiler reports 2880 x 1800.
>
> So, the question is: how can I determine the screen size of a Mac from my
> bash script in the same units like "System Events" uses?
> Or, how can I determine the factor by which I have to convert pixels into
> those other units?
I'm not sure what you're trying to do necessarily makes sense. In particular,
you're not taking into account the current screen resolution (a.k.a. display
mode). The user can select different scaling for a Retina display in System
Preferences > Displays. So, a screen with that's physically 5120x2880 pixels
is, by default, in a mode that's 2560x1440 points and 5120x2880 pixels in the
backing buffer. However, it may also be in a mode that's just 1600x900 points
with a 3200x1800-pixel backing buffer. Or a mode that's 3200x1800 points with
a 6400x3600-pixel backing buffer (which is ultimately scaled down to the
5120x2880 physical pixels of the display).
So, basically what I'm saying is that there's no fixed relationship between
points (for window sizes, etc.) and the number of physical pixels of a
display's size, even if you know the screen is a Retina display.
First, you're going to have to explain exactly what you're planning to do with
the results of your calculation. Do you really want the physical screen size?
Or do you want the size of the current display mode?
Then, you probably are going to have to use APIs to get the info you need.
However, you don't necessarily have to build a C utility for it. You can
invoke the Swift interpreter to execute code from your script. Or, you could
use Python and the PyObjC bridge.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden