无法使用AppleScript获取或设置某些应用程序的窗口大小?

nop*_*ole 8 applescript

对于某些应用程序,例如Notes或VLC,可以使用以下内容:

tell application "Notes" to get the bounds of the window 1
Run Code Online (Sandbox Code Playgroud)

如果我将上面的行放入一个文件并sudo osascript thatfilename用来调用它,它就可以了.

但对于一些应用程序,如愤怒的小鸟空间,以下将无法正常工作?

tell application "Angry Birds Space" to get the bounds of the window 1
Run Code Online (Sandbox Code Playgroud)

给出错误:

execution error: Angry Birds Space got an error: Can’t get bounds of 
  window 1. (-1728)
Run Code Online (Sandbox Code Playgroud)

这个应用程序有什么特别的东西阻止它吗?(因为它是游戏还是没有窗口1?)

我期待到获取和设置bounds或只是width一些窗口(只是宽度为一些窗口似乎有一个特定的纵横比,所以我认为它设置为特定的宽度和高度可能无法正常工作,如果长宽比ISN不对.)

小智 13

如果应用程序不可编写脚本,您将无法从中获取此类信息.如果您具有"为辅助设备启用访问权限"设置的" 系统首选项">"辅助功能"首选项,则可以使用" 系统事件"流程套件来获取/设置窗口大小,例如:

tell application "System Events" to tell application process "Angry Birds Space"
    get size of window 1
end tell
Run Code Online (Sandbox Code Playgroud)

注意:启用可访问性在macOS版本之间存在严重差异.如何在Mac OS X上启用辅助功能 是一个很好的指南.从10.14开始,您必须转到安全和隐私>辅助功能选项>隐私选项卡,然后在"允许下面的应用程序控制您的计算机"中添加该应用程序.

  • 应用程序可以提供bounds属性(如果它是可编写脚本的),但它不必 - 它提供开发人员想要的任何属性名称和值.在**系统事件**的情况下,窗口边界可以由**位置**和**大小**属性确定,其中**位置**是{left,top}的2项列表,**size**是{width,height}的2项列表. (4认同)

ada*_*one 6

愤怒的小鸟空间可以编写脚本吗?如果没有,告诉它做任何事情都不会起作用。一个类似的例子是:

tell application "Preview" to get the bounds of the window 1
Run Code Online (Sandbox Code Playgroud)

正如Red Menace指出的那样,您可以使用如下申请流程:

tell application "System Events" to tell application process "Preview"
    tell window 1
        set {size, position} to {{1280, 800}, {50, 50}}
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)