2009-02-17 89 views
3

我正在研究OS X上的窗口管理(试图实现类似WinSplit Revolution的操作),并且我需要使用applescript在给定的监视器上提取窗口的最大大小。目前我发现:AppleScript,多显示器和最大窗口大小

tell application "Safari" 
    set screen_width to (do JavaScript "screen.availWidth" in document 1) 
    set screen_height to (do JavaScript "screen.availHeight" in document 1) 
end tell 

这适用于多监视器设置的主监视器,但根本不提供辅助监视器。我也读了详细的方法here,这显然不适用于多种显示器的有效方式。有没有一种有效的方法来获得与苹果的多个显示器的最大窗口大小?

回答

2

已经有很多尝试通过读取系统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的框架方法为您提供了一个矩形,其原点位于主显示器的左下角。然后,相对于该来源给出任何二级屏幕。如果您试图确定某个窗口是否在这些边界内,则窗口位置在坐标系统内给出,其顶点位于顶部的左上角。这是我还没有弄清楚的转换过程。