예제 #1
0
async def iterm_focus_monitor(connection):
    app = await iterm2.async_get_app(connection)

    # input_lang = 'U.S.'
    async with iterm2.FocusMonitor(connection) as monitor:
        print("Focus monitoring online")
        while True:
            update = await monitor.async_get_next_update()
            window = app.current_terminal_window
            ##
            # zp("ecdbg {update.__dict__!s}")
            # if update.window_changed:
                # zp("ecdbg {update.window_changed.__dict__!s}")
                # zp("ecdbg {update.window_changed.event.__dict__!s}")
                # zp("ecdbg {window.__dict__!s}")
            ##
            if (update.active_session_changed or update.selected_tab_changed or update.window_changed) and window and window.current_tab:
                # embed(using='asyncio')
                if update.window_changed:
                    focus=update.window_changed.event.name
                    if focus == 'TERMINAL_WINDOW_BECAME_KEY':
                        # input_lang = z('input-lang-get-darwin').outrs
                        # z('input-lang-set en')
                        z('input-lang-push en')
                    else:
                        # z('input-lang-set {input_lang}')
                        z('input-lang-pop')
                    zp('reval-ec redis-cli set iterm_focus {focus} 2>&1')
                zp('reval-ec redis-cli set iterm_active_session {window.current_tab.active_session_id} 2>&1')
예제 #2
0
파일: jeff-daemon.py 프로젝트: gil/dotfiles
async def main(connection):
    connection = await iterm2.Connection.async_create()
    app = await iterm2.async_get_app(connection)

    async with iterm2.FocusMonitor(connection) as monitor:
        while True:
            update = await monitor.async_get_next_update()
            if update.window_changed and update.window_changed.event == iterm2.FocusUpdateWindowChanged.Reason.TERMINAL_WINDOW_BECAME_KEY:
                window = app.get_window_by_id(update.window_changed.window_id)
                if window and window.current_tab and window.current_tab.current_session:
                    session = window.current_tab.current_session
                    profile_name = await session.async_get_variable('profileName')
                    if profile_name == 'Jeff':
                        await session.async_send_text('\003', suppress_broadcast=True) # ctrl+c in ascii
                        await session.async_send_text('jeff\n', suppress_broadcast=True)
예제 #3
0
async def main(connection):
    app = await iterm2.async_get_app(connection)

    async def init_alternative_tab_id(window):
        first_tab = window.tabs[0]
        if not await window.async_get_variable("user.ALTERNATIVE_TAB_PREV_ID"):
            await window.async_set_variable("user.ALTERNATIVE_TAB_PREV_ID",
                                            first_tab.tab_id)
        if not await window.async_get_variable("user.ALTERNATIVE_TAB_CUR_ID"):
            await window.async_set_variable("user.ALTERNATIVE_TAB_CUR_ID",
                                            first_tab.tab_id)

    async def update_alternative_tab_id(tab_id):
        window = app.get_window_for_tab(tab_id)
        if await window.async_get_variable("user.ALTERNATIVE_TAB_CUR_ID"
                                           ) != tab_id:
            await window.async_set_variable(
                "user.ALTERNATIVE_TAB_PREV_ID", await
                window.async_get_variable("user.ALTERNATIVE_TAB_CUR_ID"))
            await window.async_set_variable("user.ALTERNATIVE_TAB_CUR_ID",
                                            tab_id)

    for window in app.terminal_windows:
        await init_alternative_tab_id(window)

    @iterm2.RPC
    async def select_alternative_tab():
        await app.get_tab_by_id(await
                                app.current_terminal_window.async_get_variable(
                                    "user.ALTERNATIVE_TAB_PREV_ID")
                                ).async_activate()

    await select_alternative_tab.async_register(connection)

    async with iterm2.FocusMonitor(connection) as mon:
        while True:
            update = await mon.async_get_next_update()
            if update.selected_tab_changed:
                await update_alternative_tab_id(
                    update.selected_tab_changed.tab_id)
            if update.window_changed:
                await init_alternative_tab_id(
                    app.get_window_by_id(update.window_changed.window_id))
예제 #4
0
 async def runFocusMon():
     async with iterm2.FocusMonitor(connection) as mon:
         while True:
             update = await mon.async_get_next_update()
             if update.selected_tab_changed:
                 SetKeyboardLanguage()
예제 #5
0
async def focus_monitor(connection: iterm2.connection.Connection):
    async with iterm2.FocusMonitor(connection) as monitor:
        while True:
            update = await monitor.async_get_next_update()
            if update.selected_tab_changed:
                print("The active tab is now {}".format(update.selected_tab_changed.tab_id))