AppleScript error: can't get window

Discussion in 'Mac Programming' started by peregrinare, Mar 4, 2012.

  1. peregrinare, Mar 4, 2012
    Last edited by a moderator: Mar 4, 2012

    macrumors newbie

    Mar 4, 2012
    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.
  2. macrumors 604

    Aug 9, 2009
    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 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:

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

    Mar 4, 2012
    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?

  4. macrumors 604

    Aug 9, 2009
    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.
  5. macrumors 6502

    May 29, 2011
    Littleton, Colorado, USA
    Take a look at using the size and position properties of the UI element (the window) via System Events, for example ( is not scriptable):

    tell application "Preview" to activate -- needs to be in front
    tell application "System Events" to tell application process "Preview"
    		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

Share This Page