[Pythonmac-SIG] trouble getting window bounds via appscript

Ned Deily nad at acm.org
Fri Feb 5 23:21:07 CET 2010


In article <4B6C8E7B.8000105 at gmail.com>,
 Todd <t.greenwoodgeer at gmail.com> wrote:
> I'd like to perform some window management via appscript on Mac OSX 
> (10.6.2).
> 
> This is pretty straightforward using AppleScript (see code#1 below). 
> However, my attempts to perform the same tasks in python appscript have 
> failed:
> 
> 1. get bounds of display
> 2. get bounds of foreground process
> 
> I can query the 'System Events' for the process list, and get the 
> foremost process...however, I cannot get the bounds from the windows. 
> (see code#2 below).
> 
> The appscript error is:
> ------------------------------------------------
> CommandError: Command failed:
>                  OSERROR: -1728
>                  MESSAGE: Can't get reference.
>                  OFFENDING OBJECT: 
> app(u'/System/Library/CoreServices/System 
> Events.app').application_processes[u'iTerm'].windows[u'todd at greenmachine: 

You need to get a windows reference from each application's object, not 
from a System Events app object:

>>> bounds_tuple = app('Terminal').windows.first.bounds()
>>> print bounds_tuple
(675, 310, 1330, 820)

-- 
 Ned Deily,
 nad at acm.org



More information about the Pythonmac-SIG mailing list