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

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

问题描述

我设置了两台显示器,我试图将应用程序的窗口定位在第二台显示器上,但我所做的一切似乎都不起作用.例如,我正在使用我的笔记本电脑并且终端窗口在屏幕上最大化.然后我插入一个外接显示器.然后我想运行 applescript 并使终端在较大的第二台显示器上最大化.

这是我现在所拥有的:

将 monitorTwoPos 设置为 {1050, -600}将 monitorTwoSze 设置为 {1200, 1920}告诉应用程序Microsoft Outlook"将窗口 1 的位置设置为 monitorTwoPos将窗口 1 的大小设置为 monitorTwoSze结束告诉

这是我得到的错误:

<前>/Users/vcutten/AppleScripts/SpacesWork.scpt:1291:1332: 执行错误:Microsoft Outlook 出现错误:无法将窗口 1 的位置设为类型说明符.(-1700)

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

奖励问题:如何遍历打开的窗口并获取它们的大小?谢谢!

解决方案

你尝试了什么?

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

设置 monitorSize 为 {800, 600}将 monitorPosition 设置为 {-800, 0}告诉应用程序系统事件"告诉进程终端"将 frontWindow 设置为第一个窗口将 frontWindow 的位置设置为 monitorPosition将 frontWindow 的大小设置为 monitorSize结束告诉结束告诉

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

希望能帮到你...

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.

Here is what I have right now:

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

Here is the error I get:

/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!

解决方案

What have you tried?

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

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天全站免登陆