diff --git a/src/askui/tools/pynput/pynput_agent_os.py b/src/askui/tools/pynput/pynput_agent_os.py index c6a28f89..bccded71 100644 --- a/src/askui/tools/pynput/pynput_agent_os.py +++ b/src/askui/tools/pynput/pynput_agent_os.py @@ -1,6 +1,8 @@ import ctypes import platform import queue +import shlex +import subprocess import time from functools import wraps from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast @@ -348,6 +350,22 @@ def set_display(self, display: int = 1) -> None: raise ValueError(error_msg) self._display = display + @override + def run_command(self, command: str, timeout_ms: int = 30000) -> None: + """ + Run a shell command. + + Args: + command (str): The command to run. + timeout_ms (int, optional): Timeout in milliseconds. Defaults to 30000. + + Raises: + subprocess.TimeoutExpired: If the command takes longer than the timeout. + subprocess.CalledProcessError: If the command returns a non-zero exit code. + """ + + subprocess.run(shlex.split(command), timeout=timeout_ms / 1000) + def _on_mouse_click( self, x: float, y: float, button: Button, pressed: bool, injected: bool ) -> None: