32 lines
989 B
Python
32 lines
989 B
Python
#!/usr/bin/env python3
|
|
import json
|
|
import sys
|
|
from gi.repository import Atspi
|
|
|
|
target, action = json.loads(sys.argv[1]), sys.argv[2]
|
|
Atspi.init()
|
|
desktop = Atspi.get_desktop(0)
|
|
found = None
|
|
def walk(node, depth=0):
|
|
global found
|
|
if found or node is None or depth > 30:
|
|
return
|
|
try:
|
|
if (node.get_name() or '') == target.get('name') and (node.get_role_name() or '') == target.get('role'):
|
|
found = node
|
|
return
|
|
for i in range(node.get_child_count()):
|
|
walk(node.get_child_at_index(i), depth + 1)
|
|
except Exception:
|
|
return
|
|
walk(desktop)
|
|
if not found:
|
|
raise SystemExit('AT-SPI target not found')
|
|
actions = found.get_action()
|
|
for i in range(actions.get_n_actions()):
|
|
if actions.get_action_name(i).lower() == action.lower():
|
|
if actions.do_action(i):
|
|
print(json.dumps({'ok': True, 'action': action}))
|
|
raise SystemExit(0)
|
|
raise SystemExit(f'AT-SPI action unavailable: {action}')
|