How to use the iterm2.rpc.async_variable function in iterm2

To help you get started, we’ve selected a few iterm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / window.py View on Github external
async def async_set_variable(self, name: str, value: typing.Any) -> None:
        """
        Sets a user-defined variable in the window.

        See the Scripting Fundamentals documentation for more information on
        user-defined variables.

        :param name: The variable's name. Must begin with `user.`.
        :param value: The new value to assign.

        :throws: :class:`RPCException` if something goes wrong.
        """
        # pylint: disable=no-member
        result = await iterm2.rpc.async_variable(
            self.connection,
            sets=[(name, json.dumps(value))],
            window_id=self.window_id)
        status = result.variable_response.status
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
async def async_get_variable(self, name: str) -> typing.Any:
        """
        Fetches a session variable.

        See the Scripting Fundamentals documentation for more information on
        variables.

        :param name: The variable's name.

        :returns: The variable's value or empty string if it is undefined.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.

        .. seealso:: Example ":ref:`colorhost_example`"
        """
        result = await iterm2.rpc.async_variable(
            self.connection, self.__session_id, [], [name])
        status = result.variable_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
        return json.loads(result.variable_response.values[0])
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / tab.py View on Github external
async def async_get_variable(self, name: str) -> typing.Any:
        """
        Fetches a tab variable.

        See Badges documentation for more information on variables.

        :param name: The variable's name.

        :returns: The variable's value or `None` if it is undefined.

        :throws: :class:`RPCException` if something goes wrong.

        .. seealso:: Example ":ref:`sorttabs_example`"
        """
        result = await iterm2.rpc.async_variable(
            self.connection, gets=[name], tab_id=self.__tab_id)
        status = result.variable_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
        return json.loads(result.variable_response.values[0])
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / app.py View on Github external
async def async_get_variable(self, name: str) -> typing.Any:
        """
        Fetches the value of a variable from the global context.

        See `Scripting Fundamentals
        `_ for
        details on variables.

        :param name: The variable's name.

        :returns: The variable's value or empty string if it is undefined.

        :throws: :class:`RPCException` if something goes wrong.
        """
        result = await iterm2.rpc.async_variable(
            self.connection, gets=[name])
        status = result.variable_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
        return json.loads(result.variable_response.values[0])
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / app.py View on Github external
async def async_get_variable(
        connection: iterm2.connection.Connection, name: str) -> typing.Any:
    """
    Fetches the value of a variable from the global context.

    See `Scripting Fundamentals
    `_
    for details on variables.

    :param name: The variable's name.

    :returns: The variable's value or empty string if it is undefined.

    :throws: :class:`RPCException` if something goes wrong.
    """
    result = await iterm2.rpc.async_variable(connection, gets=[name])
    status = result.variable_response.status
    # pylint: disable=no-member
    if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
        raise iterm2.rpc.RPCException(
            iterm2.api_pb2.VariableResponse.Status.Name(status))
    return json.loads(result.variable_response.values[0])
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / tab.py View on Github external
async def async_set_variable(self, name: str, value: typing.Any) -> None:
        """
        Sets a user-defined variable in the tab.

        See the Scripting Fundamentals documentation for more information on
        user-defined variables.

        :param name: The variable's name. Must begin with `user.`.
        :param value: The new value to assign.

        :throws: :class:`RPCException` if something goes wrong.
        """
        result = await iterm2.rpc.async_variable(
            self.connection,
            sets=[(name, json.dumps(value))],
            tab_id=self.__tab_id)
        status = result.variable_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / window.py View on Github external
async def async_get_variable(self, name: str) -> typing.Any:
        """
        Fetches a window variable.

        See the Scripting Fundamentals documentation for more information on
        variables.

        :param name: The variable's name.

        :returns: The variable's value or empty string if it is undefined.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
        """
        # pylint: disable=no-member
        result = await iterm2.rpc.async_variable(
            self.connection, window_id=self.__window_id, gets=[name])
        status = result.variable_response.status
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))
        return json.loads(result.variable_response.values[0])
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / app.py View on Github external
async def async_set_variable(self, name: str, value: typing.Any) -> None:
        """
        Sets a user-defined variable in the application.

        See the Scripting Fundamentals documentation for more information on
        user-defined variables.

        :param name: The variable's name. Must begin with `user.`.
        :param value: The new value to assign.

        :throws: :class:`RPCException` if something goes wrong.
        """
        result = await iterm2.rpc.async_variable(
            self.connection,
            sets=[(name, json.dumps(value))])
        status = result.variable_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.VariableResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.VariableResponse.Status.Name(status))