Gnome (Ubuntu):如何从终端使用命令行将程序窗口置于最前面?

GJ.*_*GJ. 16 linux gnome window-manager ubuntu

我有一个特定的工作环境,有几十个打开的 Windows。如何以编程方式或使用命令行将具有已知名称/标题的窗口置于前面?

fra*_*ous 14

我曾经使用wmctrl -a <name>,它工作正常,但最近切换到xdotool,例如:

xdotool search --name <name-or-regex-for-name> windowraise

它还有许多其他功能。

安装:

sudo apt-get install xdotool

  • `xdotool windowraise` 将窗口带到最前面,但不会将焦点放在窗口上或切换到带有窗口的桌面。相反,`windowactivate` 将完成所有三个操作。 (6认同)

dig*_*txp 6

好吧,在sudo apt-get install wmctrl-ing之后,您可以使用这个 bash 脚本:

#! /bin/bash

WINTITLE="Mail/News" # Main Thunderbird window has this in titlebar
PROGNAME="mozilla-thunderbird" # This is the name of the binary for t-bird

# Use wmctrl to list all windows, count how many contain WINTITLE,
# and test if that count is non-zero:

if [ `wmctrl -l | grep -c "$WINTITLE"` != 0 ]
then
wmctrl -a "$WINTITLE" # If it exists, bring t-bird window to front
else
$PROGNAME & # Otherwise, just launch t-bird
fi
exit 0
Run Code Online (Sandbox Code Playgroud)

我在这里找到的

  • 不需要括号和反引号:`if ! wmctrl -l | grep -q "$WINTITLE"` (4认同)