使用双显示器使用AppleScript定位窗口 [英] Positioning a window with AppleScript using dual monitors

查看:228
本文介绍了使用双显示器使用AppleScript定位窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了两个监视器,我试图将应用程序的窗口放置在第二个监视器中,但是我似乎无济于事.例如,我正在使用笔记本电脑,并且终端窗口在屏幕上已最大化.然后,我插入一个外接显示器.然后,我想运行applescript,并使终端在更大的第二台显示器上最大化.

I have two monitors set up and I am trying to position the window of an application in the second monitor but nothing I do seems to work. For example I am using my laptop and the terminal window is maximized on the screen. Then I plug in an external monitor. I then want to run the applescript and have the terminal maximize on the larger second monitor.

这是我现在拥有的:

set monitorTwoPos to {1050, -600}
set monitorTwoSze to {1200, 1920}

tell application "Microsoft Outlook"
    set position of window 1 to monitorTwoPos
    set size of window 1 to monitorTwoSze
end tell

这是我得到的错误:


/Users/vcutten/AppleScripts/SpacesWork.scpt:1291:1332: execution error: 
Microsoft Outlook got an error: Can’t make position of window 1 into type specifier. (-1700)

我很确定我只是在使用设置位置和设置大小完全错误:(当我使用边界时,它的工作原理...

I'm pretty sure I'm just using set position and set size completely wrong :( When I used bounds it kind of works...

奖金问题: 如何遍历打开的窗口并确定其大小?谢谢!

Bonus Question: How can I loop through the open windows and get their size? Thanks!

推荐答案

您尝试了什么?

我认为要解决此问题,您需要计算第二台显示器的屏幕尺寸和坐标.例如,您的主监视器从位置{0,0}开始.因此,第二台显示器的起始位置必须有所不同,您需要找到它.幸运的是,我编写了一个工具,可以为您提供显示器的起始坐标和屏幕尺寸.一旦有了尺寸和位置,就很简单.系统事件可以设置窗口的大小和位置,因此您可以执行以下操作...

I think to solve this you need to calculate the screen size and coordinates of the second monitor. For example, your main monitor starts at position {0,0}. So the starting position of the second monitor has to be something different and you need to find that. Luckily I have written a tool that will give you both the starting coordinates and screen size of your monitors. Once you have the size and position then it's simple. System events can set the size and position of a window so you could do something like this...

set monitorSize to {800, 600}
set monitorPosition to {-800, 0}

tell application "System Events"
    tell process "Terminal"
        set frontWindow to first window
        set position of frontWindow to monitorPosition
        set size of frontWindow to monitorSize
    end tell
end tell

因此从上面的脚本中,您只需要size和position变量.您可以在此处获得名为hmscreens的工具,它将为您提供这些工具.您可能需要根据屏幕是从左下角还是从左上角进行测量来对坐标进行一些调整,但这只是简单的数学运算.

So from the above script you just need the size and position variables. You can get my tool here called hmscreens which will give you those. You may need to do some adjusting of the coordinates depending on if the screen is measured from the lower left corner or upper left, but that's just simple math.

我希望对您有帮助...

I hope that helps...

这篇关于使用双显示器使用AppleScript定位窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆