已经有很多尝试通过读取系统 plist 文件来获取显示器尺寸。见http://macscripter.net/viewtopic.php?id=15425
如果您有权访问 AppleScript Studio (ASS) 条款,则可以对 NSScreen 进行方法调用以获取所有监视器,然后询问它们的大小。在纯 AppleScript 中使用 ASS 术语的最简单方法是在 Xcode 中编译一个空的 ASS 应用程序。在这个例子中,我创建了一个简单的 ASS 应用程序名称 ASSAccess,它可以让我访问 ASS 术语:
tell application "ASSAccess"
-- The first item in this list will be your main monitor
set screensArray to call method "screens" of class "NSScreen"
set Displays to {}
if {} is not screensArray then
repeat with displayNo from 1 to (count screensArray)
-- call visibleFrame instead to take into account the Dock and menubar
set dims to call method "frame" of (item displayNo of screensArray)
copy dims to end of Displays
end repeat
end if
end tell
现在,我在这些维度上遇到的问题是坐标系。NSScreen 的 frame 方法为您提供了一个矩形,其原点位于主监视器的左下角。然后,相对于该原点给出任何辅助屏幕。如果您试图确定窗口是否在这些范围内,则窗口位置在坐标系内给出,原点位于左上角。这是我还没有弄清楚的一大堆转换。