【问题标题】:iTerm2 Transparent transparent background for inactive windowsiTerm2 非活动窗口的透明透明背景
【发布时间】:2018-07-06 08:25:08
【问题描述】:

本机 MacOS Terminal 能够为非活动和活动窗格设置透明度。 iTerm2 具有活动背景的透明度,由于某种原因,我找不到非活动背景或maybe there isn't any?。我知道,iTerm2 有 DIM inactive split panes,但我正在寻找的是透明度。

感谢您的帮助。

【问题讨论】:

  • 有一个调光量栏,您可以针对不活动的拆分窗格进行调整。这就是你要找的吗?
  • @yash 它到底在哪里?
  • 它在首选项 -> 外观 -> 调光下。我正在为您链接屏幕截图ibb.co/dohF6S

标签: macos terminal iterm2 iterm


【解决方案1】:

this blog 上找到了答案,但为了保存,我会在这里重复一遍。

  1. 打开 iTerm2 的首选项,使用菜单或 +,
  2. 从菜单栏中选择个人资料
  3. 选择窗口标签
  4. 拖动透明度滑块以满足您的需要

【讨论】:

  • 这会影响所有窗口,包括活动窗口,OP 只想更改 inactive 窗口的透明度。
  • 不适合我...我正在更改透明度,但 iterm2 窗口仍然不透明...知道吗?
  • 这不能回答问题。 OP 想要 Mac 终端具有的行为:为非活动窗口添加透明度。 AFAICS 这是不可能的,但@bjfletcher 的答案更接近。
  • 在设置新机器时也无法正常工作。我在某处读到你必须然后按 cmd+B 瞧,它起作用了! (不记得以前必须在我的旧机器上这样做)
【解决方案2】:

首选项→外观→调光→调光量

【讨论】:

  • 接近替代,但这并不完全相同。它应用调光(如灰色投射),而不是点击效果不透明和不活动时透明效果。
【解决方案3】:

编辑:是原始脚本版本中的一个错误,他们没有处理标签中多个会话的情况。修复和重构:)


前面的每个答案都得到了一块拼图。一个改变透明度,但是是静态的;当窗口处于非活动状态时,其他变暗,而不是更改透明度。

要获得所需的行为(根据窗口焦点更改透明度),您需要使用 iTerm2 的 Python API 编写脚本,并将其保存为 AutoLaunch 脚本:

#!/usr/bin/env python3.7

import iterm2

# Store window change event reason objects in more convenient variables
window_selected = [iterm2.FocusUpdateWindowChanged.Reason.TERMINAL_WINDOW_BECAME_KEY]


async def update_tab_transparency(connection, tab, reason):
    # Apply to any and all sessions in tab
    for session in tab.sessions:
        profile = await session.async_get_profile()
        change = iterm2.LocalWriteOnlyProfile()

        # For window change events bringing a window into focus,
        # change transparency to zero
        if reason in window_selected:
            change.set_transparency(0)

        # For window change events taking a window out of focus,
        # make sure transparency matches the original profile
        else:
            # But, only need to do anything if the profile has been changed
            # from the original
            if profile.original_guid:
                original = await iterm2.Profile.async_get(
                    connection, [profile.original_guid]
                )
                change.set_transparency(original[0].transparency)

        await session.async_set_profile_properties(change)


async def main(connection):
    app = await iterm2.async_get_app(connection)

    # Initialize for first window
    window = app.current_window
    if window and window.current_tab:
        tab = window.current_tab
        reason = window_selected[0]
        await update_tab_transparency(connection, tab, reason)

    async with iterm2.FocusMonitor(connection) as mon:
        while True:
            # Block until a tab or window change
            update = await mon.async_get_next_update()

            # When switching to a new tab, treat as selecting a window
            if update.selected_tab_changed:
                tab = app.get_tab_by_id(update.selected_tab_changed.tab_id)
                reason = window_selected[0]

            # For window change events, use the provided event reason
            elif update.window_changed:
                window = app.get_window_by_id(update.window_changed.window_id)
                tab = window.current_tab
                reason = update.window_changed.event

            # For other focus change events, do nothing
            else:
                continue

            if tab:
                await update_tab_transparency(connection, tab, reason)


iterm2.run_forever(main)

有关using Python scripts 的详细信息,请参阅 iTerm 文档

您想在个人资料上设置所需的透明度,并选中“新 Windows 设置”的“使用透明度”框。这听起来违反直觉,但似乎无法通过 API 切换“使用透明度”设置,因此脚本会在创建时快速将窗口切换为不透明。

至少在我的机器上,当第一次选择时,窗口会短暂闪烁,但我不确定我是否能对此做些什么。


注意:macOS 当前(11.6,Big Sur)处理窗口的方式与此相反——它使活动窗口透明(至少,它们的某些部分)和非活动窗口不透明(并褪色)。尝试在 Safari 中打开一个新标签页。这说得通!透明度创造了一种深度感。看到活动窗口后面有窗口强调它在它们前面。

要获得此行为,请使用以下脚本。这种变体更简单,而且运行起来似乎更顺畅(没有闪烁)。如果您将模糊设置为最大,透明度约为 25,则效果最佳。

#!/usr/bin/env python3.7

import iterm2

# Store window change event reason objects in more convenient variables
window_selected = [iterm2.FocusUpdateWindowChanged.Reason.TERMINAL_WINDOW_BECAME_KEY]


async def update_tab_transparency(connection, tab, reason):
    # Apply to any and all sessions in tab
    for session in tab.sessions:
        profile = await session.async_get_profile()
        change = iterm2.LocalWriteOnlyProfile()

        # For window change events bringing a window into focus,
        # make sure transparency matches the original profile
        if reason in window_selected:
            # But, only need to do anything if the profile has been changed
            # from the original
            if profile.original_guid:
                original = await iterm2.Profile.async_get(
                    connection, [profile.original_guid]
                )
                change.set_transparency(original[0].transparency)

        # For window change events taking a window out of focus,
        # change transparency to zero
        else:
            change.set_transparency(0)

        await session.async_set_profile_properties(change)


async def main(connection):
    app = await iterm2.async_get_app(connection)

    async with iterm2.FocusMonitor(connection) as mon:
        while True:
            # Block until a window change
            update = await mon.async_get_next_update()
            if update.window_changed:
                window = app.get_window_by_id(update.window_changed.window_id)
                tab = window.current_tab

                if tab:
                    reason = update.window_changed.event
                    await update_tab_transparency(connection, tab, reason)


iterm2.run_forever(main)

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多