我最近从 KDE4 转移到 Gnome3。在 KDE 中,您可以创建特定于应用程序的键盘快捷键来提升窗口。我通常为 firefox、thunderbird、我的终端等创建一个。这样在窗口之间切换是闪电般的快速。Gnome 似乎没有那种功能。我也不喜欢 Gnome3 的窗口切换方案(alt-tab)。
因此我想知道是否可以通过 DBUS 提高窗口?如果是,则可以编写脚本并为其分配键盘快捷键。
我在 Fluxbox wiki 上找到了一个脚本,该脚本用于wmctrl查找应用程序并在其已运行时提升其窗口。否则,脚本将启动应用程序。我正在使用该脚本并进行一些调整来支持参数,我已在我的博客上记录了这些参数。
确保wmctrl已安装。
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)将以下脚本添加到您的路径(可能在 中$HOME/bin/find_app.sh),并使其可执行。
#!/bin/bash
# Find_app
# Author: Lucas van Staden (lvs at dedmeet.com / http://www.dedmeet.com)
# This little script will try and find the application attempting to start
# in the running processes, and if found, focus the application
# if not found, a new instance will start
# usage:
# find_app.sh <application with full path>
# params
# 1 - application to start (full path)
# helper applications
DOLLARONE=$(echo $1 | sed -e 's/[\t ]*$//') #Delete trailing spaces
WMCTRL=`which wmctrl`;
GREP=`which grep`;
APPLICATION=$(echo $DOLLARONE | cut -d ' ' -f 1)
if [ "x$APPLICATION" != "x$DOLLARONE" ]; then
APPARGS=$(echo $DOLLARONE | cut -d ' ' -f 2)
fi
BASENAME=`basename $APPLICATION`;
BASENAME=`echo $BASENAME | tr "[:upper:]" "[:lower:]"`
FOUND=0;
function findwindow {
# 1 = BASENAME
# 2 = WMCTRL
# 3 = GREP
IFS=$'\n';
for RUNNING in `$2 -l -x`
do
if [ `echo $RUNNING | tr "[:upper:]" "[:lower:]" | $3 -c $DOLLARONE` -gt 0 ]
then
HOSTNAME=`hostname`
WINDOW=${RUNNING#*${HOSTNAME} }
$2 -a $WINDOW
FOUND=1;
fi;
done
}
if [ "x$APPARGS" = "x" ]; then
findwindow $BASENAME $WMCTRL $GREP;
if [ $FOUND -eq 0 ]
then
$APPLICATION &
sleep 2;
# Try and find the application, after opened
findwindow $BASENAME $WMCTRL $GREP;
if [ $FOUND -eq 0 ]
then
# Still not found, wait a bit more, and try again
sleep 3;
findwindow $BASENAME $WMCTRL $GREP;
fi
fi
else
$APPLICATION $APPARGS &
fi
Run Code Online (Sandbox Code Playgroud)更新您想要具有单一快捷方式启动和启动的应用程序的桌面入口文件,以便通过上述脚本调用应用程序。
例如:
cp /usr/share/applications/firefox.desktop ~/.local/share/applications/
Run Code Online (Sandbox Code Playgroud)
编辑firefox.desktop并~/.local/share/applications/更改该Exec行以引用find_app.sh:
Exec=find_app.sh "firefox %u"
Run Code Online (Sandbox Code Playgroud)现在为您的默认浏览器添加键盘快捷键:
系统设置| 键盘| 快捷方式 | 发射器| 启动网页浏览器
重新启动 gnome shell:按下Alt r可显示运行对话框。键入r并按Enter。
您现在应该能够使用单个键盘快捷键启动/启动浏览器。