Can't get or set the window size of some apps using AppleScript?

For some applications, such as Notes or VLC, you can use the following:

tell application "Notes" to get the bounds of the window 1 

if I put the above line in a file and use sudo osascript thatfilename to call it, it works.

But for some applications, such as Angry Birds Space, the following will not work?

 tell application "Angry Birds Space" to get the bounds of the window 1 

with an error:

 execution error: Angry Birds Space got an error: Can't get bounds of window 1. (-1728) 

Is there anything special about this app that prevents it? (because it is a game or it does not have window 1?)

I am learning how to get and set bounds or just the width some window (only the width, since some window seems to have a specific aspect ratio, so I think it sets a certain width and the height may not work if the aspect ratio is wrong).

+6
source share
2 answers

If the application does not support scripting, you will not be able to obtain such information. If you have installed System Preferences> Accessibility for Enable Access for Auxiliary Devices, you can use the System Events process set to get / set the window size, for example:

 tell application "System Events" to tell application process "Angry Birds Space" get size of window 1 end tell 

Note. Enabling accessibility is highly dependent on the MacOS version. How to enable Accessibility on Mac OS X is a good guide. Starting from 10.14, you need to go to the section "Security and Privacy"> "Accessibility"> the tab "Privacy" and add the application to "Allow applications below to control your computer."

+11
source

Is Angry Birds Space Scriptable? If not, saying that this should not work. A similar example could be:

 tell application "Preview" to get the bounds of the window 1 

As Red Menace points out, you can use the application process as follows:

 tell application "System Events" to tell application process "Preview" tell window 1 set {size, position} to {{1280, 800}, {50, 50}} end tell end tell 
+4
source

All Articles