【问题标题】:How to automatically start programs in a specific order?如何按特定顺序自动启动程序?
【发布时间】:2019-02-07 04:31:58
【问题描述】:

我的 i3 配置文件中有这些行:

# Startup applications.
exec firefox
exec gnome-terminal
exec nautilus

这些行按预期启动 firefox、gnome-terminal 和 nautilus,但它们的启动顺序是不可预测的。有没有办法以使窗口按我想要的顺序显示的方式启动这些应用程序? (即 firefox,然后是 gnome-terminal,然后是 nautilus)。

【问题讨论】:

    标签: i3


    【解决方案1】:

    请参阅Layout saving in i3

    将此添加到 i3 配置文件中:

    # Create specific layout for applications.
    exec --no-startup-id "i3-msg 'workspace 1; append_layout ~/.config/i3/workspace-1.json'"
    # Start applications.
    exec firefox
    exec gnome-terminal
    

    创建~/.config/i3/workspace-1.json:

    // Layout of a workspace.
    {
        "layout": "tabbed",
        // To get a window's class name, run xprop and click on the window.
        // You will see the following output:
        //     WM_CLASS(STRING) = "InstanceName", "ClassName"
        // Alternatively, "swallow" by the window's title.
        "nodes": [
            {"swallows": [{"class": "^Firefox$"}]},
            {"swallows": [{"class": "^Gnome-terminal$"}]}
        ]
    }
    

    【讨论】:

      【解决方案2】:

      您可以save layouts 以便每个应用程序都被预定义的窗口容器捕获。使其真正自动化需要一些额外的脚本。我的配置示例:

      i3 配置

      assign [class="^Vivaldi-stable$"] 1
      assign [class="^Keepassx2$"] 2
      assign [class="^Thunderbird$"] 2
      
      ....
      
      # last line
      exec ~/.config/i3/restore.sh &
      

      restore.sh

      #!/bin/sh
      
      for layout in ~/.config/i3/layouts/*; do
        i3-msg "workspace $(basename "$layout" .json); append_layout $layout"
      done
      
      (vivaldi-stable &)
      (keepassxc &)
      (thunderbird &)
      

      如果你想看完整版,我的点文件是on GitHub

      【讨论】:

      • 有没有办法让指定的窗口获得最终焦点?例如,我可能希望 Thunderbird 在所有程序启动后自动获得焦点。
      • 使用i3-msg:调用i3-msg '[class="^Thunderbird$"] focus'结束恢复脚本。
      猜你喜欢
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 2012-02-06
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 2012-02-01
      相关资源
      最近更新 更多