PDA

View Full Version : AppleScript error: can't get window




peregrinare
Mar 4, 2012, 04:25 AM
Hi everyone. There are apps that I want to position/size with AppleScript, but they generate an error saying "can't get window." Do you know how to fix this?

For example, if I write:

tell application "sparrow" to get bounds of front window

The error is:

"Sparrow got an error: Can’t get window 1." number -1728 from window 1.



chown33
Mar 4, 2012, 09:31 AM
What have you tried to solve the problem?

Maybe Sparrow isn't scriptable.

The first thing to try is opening the application's scripting dictionary in AppleScript Editor. Choose "Open Dictionary ..." from its File menu. Choose Sparrow.app from the list of applications. If you don't see a window class, then it doesn't support scriptable windows.

You should always refer to the actual scripting dictionary of an app. Otherwise you're just guessing.


The second thing to try is searching. Google search terms: mac os sparrow script

First result:
http://dinhviethoa.tumblr.com/post/5967294192/applescript-with-sparrow

May 29, 2011: Currently, Sparrow only supports sending emails using AppleScript. Other scripting features will be added in further versions. ...

peregrinare
Mar 6, 2012, 02:34 AM
Thanks. I searched for the error code rather than the app. So, if an app does not support the window class, what are the ways to position the window precisely?

What have you tried to solve the problem?

Maybe Sparrow isn't scriptable.

The first thing to try is opening the application's scripting dictionary in AppleScript Editor. Choose "Open Dictionary ..." from its File menu. Choose Sparrow.app from the list of applications. If you don't see a window class, then it doesn't support scriptable windows.

You should always refer to the actual scripting dictionary of an app. Otherwise you're just guessing.


The second thing to try is searching. Google search terms: mac os sparrow script

First result:
http://dinhviethoa.tumblr.com/post/5967294192/applescript-with-sparrow

May 29, 2011: Currently, Sparrow only supports sending emails using AppleScript. Other scripting features will be added in further versions. ...

chown33
Mar 6, 2012, 09:29 AM
Thanks. I searched for the error code rather than the app. So, if an app does not support the window class, what are the ways to position the window precisely?

Look at its scripting dictionary. There is no substitute for doing this. You will have to look.

If you see something in the scripting dictionary relevant to windows and positions, use it. If you don't, then window positions are almost certainly unscriptable.

If you don't understand the structure of a scripting dictionary, then open TextEdit's, or Finder's, or some app whose scripting terms you already recognize. Learn by example.

I don't have Sparrow, so you have to do the looking yourself.

Red Menace
Mar 6, 2012, 10:43 AM
Take a look at using the size and position properties of the UI element (the window) via System Events, for example (Preview.app is not scriptable):

tell application "Preview" to activate -- needs to be in front
tell application "System Events" to tell application process "Preview"
try
get properties of window 1
set size of window 1 to {640, 480}
on error errmess
log errmess
-- no window open
end try
end tell