Mis*_*o21 6 scripts window-manager unity launcher window
我试图控制 Ubuntu 14.4.1 Launcher 的行为。我希望它在每次我有像 firefox maxmaized 这样的浏览器窗口时自动隐藏。我找到了这个解决方案:
#!/bin/bash
## Change value of "hide" to the command which worked for you to hide the panel
hide='gsettings set com.canonical.Unity2d.Launcher hide-mode 1;'
## Change value of "show" to the command which worked for you to show the panel when it was hidden
show='gsettings set com.canonical.Unity2d.Launcher hide-mode 0;'
## Look for the grep value, add a new browser or application name followed by "\|" eg: 'firefox\|google\|chromium'
while [ 1 ]
do z=$(wmctrl -l -p | grep -i 'firefox\|google');
if [ -n "$z" ]; then
eval $hide
else
eval $show
fi;
sleep 2;
done;
Run Code Online (Sandbox Code Playgroud)
但似乎太老了,无法工作,然后我发现了这个
我试图将这两个脚本组合在一起,所以这是我所做的:
#!/bin/bash
AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if [[ $AUTOHIDE -eq 1 ]]
then
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
fi
## Look for the grep value, add a new browser or application name followed by "\|" eg: 'firefox\|google\|chromium'
while [ 1 ]
do z=$(wmctrl -l -p | grep -i 'firefox\|google');
if [ -n "$z" ]; then
eval $hide
else
eval $show
fi;
sleep 2;
done;
Run Code Online (Sandbox Code Playgroud)
但是脚本不起作用。任何人都可以向我完善这个脚本并让它工作吗?
下面是两个版本的脚本,用于在应用程序的窗口最大化时自动隐藏启动器。脚本在 14.04 / 14.10 /16.04 上测试
两个脚本都识别要图标化的窗口,然后没有理由自动隐藏,并且两个脚本都工作特定于工作区;发射只有切换到工作区的自动隐藏这里居然一个或多个窗口的最大化。
这些脚本用于wmctrl
映射当前打开的窗口。您可能需要安装它:
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)
以下两个脚本均于 2017 年 3 月更新/重写。
1.“基本”版本,作用于所有应用程序的最大化窗口
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)
2. 应用特定版本:
#!/usr/bin/env python3
import subprocess
import time
mx = "_NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ"
key = ["org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/",
"launcher-hide-mode"]
def get(cmd):
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass
def force_get(cmd):
# both xprop and wmctrl break once and a while, this is to retry if so
val = None
while not val:
val = get(cmd)
return val
def get_res():
# look up screen resolution
scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2
return [int(n) for n in scrdata[resindex].split("+")[0].split("x")]
res = get_res()
hide1 = False
while True:
time.sleep(2)
hide = False
wlist = [l.split() for l in force_get(["wmctrl", "-lpG"]).splitlines()]
# only check windows if any of the apps is running
for w in wlist:
xpr = force_get(["xprop", "-id", w[0]])
if all([
mx in xpr, not "Iconic" in xpr,
0 <= int(w[3]) < res[0], 0 <= int(w[4]) < res[1],
]):
hide = True
break
if hide != hide1:
nexts = "0" if hide == False else "1"
currset = get(["gsettings", "get", key[0], key[1]])
if nexts != currset:
subprocess.Popen([
"gsettings", "set", key[0], key[1], nexts
])
hide1 = hide
Run Code Online (Sandbox Code Playgroud)
将其中一个脚本复制到一个空文件中,
[设置,如果您选择了第二个,则隐藏您的应用程序]
并将其另存为autohide.py
.
通过以下命令运行它:
python3 /path/to/autohide.py
Run Code Online (Sandbox Code Playgroud)
如果它表现得如您所愿,请将其添加到您的启动应用程序中。
注意如果您将其用作启动应用程序,则应取消注释该行:
time.sleep(10)
Run Code Online (Sandbox Code Playgroud)
在脚本的头部部分。如果在桌面完全加载之前调用该脚本,则该脚本可能会崩溃。根据您的系统更改值 (10)。
在循环中,脚本:
(仅)如果需要更改隐藏模式,脚本会更改设置。