Window API
- class autokey.scripting.Window(mediator)[source]
Basic window management using wmctrl
Note: in all cases where a window title is required (with the exception of wait_for_focus()), two special values of window title are permitted:
- ACTIVE:
select the currently active window
- SELECT:
select the desired window by clicking on it
- activate(title, switchDesktop=False, matchClass=False)[source]
Activate the specified window, giving it input focus
Usage:
window.activate(title, switchDesktop=False, matchClass=False)
If switchDesktop is False (default), the window will be moved to the current desktop and activated. Otherwise, switch to the window’s current desktop and activate it there.
- Parameters:
title – window title to match against (as case-insensitive substring match)
switchDesktop – whether or not to switch to the window’s current desktop
matchClass – if True, match on the window class instead of the title
- close(title, matchClass=False)[source]
Close the specified window gracefully
Usage:
window.close(title, matchClass=False)
- Parameters:
title – window title to match against (as case-insensitive substring match)
matchClass – if True, match on the window class instead of the title
- get_active_class()[source]
Get the class of the currently active window
Usage:
window.get_active_class()
- Returns:
the class of the currentle active window
- Return type:
str
- get_active_geometry()[source]
Get the geometry of the currently active window
Usage:
window.get_active_geometry()
- Returns:
a 4-tuple containing the x-origin, y-origin, width and height of the window (in pixels)
- Return type:
tuple(int, int, int, int)
- get_active_title()[source]
Get the visible title of the currently active window
Usage:
window.get_active_title()
- Returns:
the visible title of the currentle active window
- Return type:
str
- move_to_desktop(title, deskNum, matchClass=False)[source]
Move the specified window to the given desktop
Usage:
window.move_to_desktop(title, deskNum, matchClass=False)
- Parameters:
title – window title to match against (as case-insensitive substring match)
deskNum – desktop to move the window to (note: zero based)
matchClass – if True, match on the window class instead of the title
- resize_move(title, xOrigin=-1, yOrigin=-1, width=-1, height=-1, matchClass=False)[source]
Resize and/or move the specified window
Usage:
window.close(title, xOrigin=-1, yOrigin=-1, width=-1, height=-1, matchClass=False)
Leaving and of the position/dimension values as the default (-1) will cause that value to be left unmodified.
- Parameters:
title – window title to match against (as case-insensitive substring match)
xOrigin – new x origin of the window (upper left corner)
yOrigin – new y origin of the window (upper left corner)
width – new width of the window
height – new height of the window
matchClass – if True, match on the window class instead of the title
- set_property(title, action, prop, matchClass=False)[source]
Set a property on the given window using the specified action
Usage:
window.set_property(title, action, prop, matchClass=False)
Allowable actions:
add, remove, toggle
Allowable properties: C{modal, sticky, maximized_vert, maximized_horz, shaded, skip_taskbar, skip_pager, hidden, fullscreen, above}- Parameters:
title – window title to match against (as case-insensitive substring match)
action – one of the actions listed above
prop – one of the properties listed above
matchClass – if True, match on the window class instead of the title
- switch_desktop(deskNum)[source]
Switch to the specified desktop
Usage:
window.switch_desktop(deskNum)
- Parameters:
deskNum – desktop to switch to (note: zero based)
- wait_for_exist(title, timeOut=5)[source]
Wait for window with the given title to be created
Usage:
window.wait_for_exist(title, timeOut=5)
If the window is in existence, returns True. Otherwise, returns False if the window has not been created by the time the timeout has elapsed.
- Parameters:
title – title to match against (as a regular expression)
timeOut – period (seconds) to wait before giving up
- Return type:
boolean
- wait_for_focus(title, timeOut=5)[source]
Wait for window with the given title to have focus
Usage:
window.wait_for_focus(title, timeOut=5)
If the window becomes active, returns True. Otherwise, returns False if the window has not become active by the time the timeout has elapsed.
- Parameters:
title – title to match against (as a regular expression)
timeOut – period (seconds) to wait before giving up
- Return type:
boolean