我刚切换到Linux,并且正在设置笔记本电脑。在Windows中,我使用AutoHotkey快捷方式执行以下操作:
-在未激活的情况下打开“ chrome”。
-最小化前景中的“ chrome”。
-当窗口不处于活动状态时,将其置于前台。
我在“自动键”中使用以下代码,效果很好,但是如果我可以使用简单的bash脚本执行此操作,我会喜欢的:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'google-chrome' in output:
winClass = window.get_active_class()
if winClass == 'google-chrome.Google-chrome':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a google-chrome")
else:
system.exec_command("google-chrome")
#end script
现在,我试图将其转换为bash代码,但是我陷入了检查chrome是否在前台运行的问题。我想到了以下伪代码,但是找不到正确的shell命令:
if chrome is not open
open chrome
else
if chrome is on foreground
minimize chrome
else
bring chrome to foreground
end
我试图通过使用Linux“快捷方式”应用程序中的shell脚本在Linux中获得此行为。但是直到现在,我仍无法找到一种方法来检查Google-chrome是否在前台。我尝试使用“ xdotools”包,但这似乎不起作用:
if ($(xdotool search --name "Google Chrome") -eq $(xdotool getactivewindow))
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -x -a google-chrome
end
您可能对实现此目标的最佳方法有一些建议吗?我现在有以下成分:
要打开google-chrome,请使用:
google-chrome &
为了使Google-chrome最小化,我使用:
xdotool windowminimize $(xdotool getactivewindow)
为了最大化Google-chrome,我使用:
wmctrl -x -a google-chrome
而且我认为我需要使用类似这样的方法来检查chrome是否在前景中:
wmctrl -lx
xdotool search --name "Google Chrome"
xdotool getactivewindow
enter code here
在此先感谢您,
问候,里克,
系统信息:桌面:Hp Zbook G3 studio发行者ID:Ubuntu说明:Ubuntu Bionic Beaver(开发分支)版本:18.04代号:bionic
我从另一个论坛的用户那里收到了我的问题的答案。
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句