不幸的是,nautilus 不提供命令行选项来读取其窗口的打开目录,也没有任何选项可以将现有窗口发送到另一个目录。由于您无法记住您没有看到的内容,因此我们一见钟情的选择已经不多了。
然而
我们确实有xdotool,不是做没有做的事nautilus,而是至少伪造您所描述的行为。如果您不知道它是如何完成的,我们可以以“您会相信”的方式做到这一点。
尽管下面的解决方案在重新启动后无法生存,但在一个会话中很可能“记住”(可能是选项卡式)窗口和所有打开的目录。既然你提到对此感兴趣作为“第二选择”,那就是。
尽管我们无法关闭窗口并保留其选项卡和打开的目录,但我们可以借助xdotool.
如果我们随后nautilus以这样一种方式更改启动器的行为:它首先寻找可能的未映射窗口进行重新映射,然后再打开一个新窗口,那么实际上我们将拥有与记住上次使用的窗口完全相同的行为nautilus。
将下面的脚本复制到一个空文件中,另存为 remember.py
#!/usr/bin/env python3
import subprocess
import os
app = "nautilus"
wfile = os.environ["HOME"]+"/.unmapped_"+app
def get(cmd):
# simply a helper function
return subprocess.check_output(cmd).decode("utf-8").strip()
def check_windowtype(w_id):
# check the type of window; only unmap "NORMAL" windows
return "_NET_WM_WINDOW_TYPE_NORMAL" in get(["xprop", "-id", w_id])
def get_pid(app):
# (try to) get the pid of the application
try:
return get(["pgrep", app])
except subprocess.CalledProcessError:
pass
def get_matches(pid):
# get the window list, select the valid (real) app's windows
ws = get(["wmctrl", "-lpG"]).splitlines()
matches = [w.split() for w in ws if pid in w]
return [w for w in matches if check_windowtype(w[0]) == True]
try:
# try to read the file with unmapped windows
wininf = [l.split() for l in open(wfile).readlines()]
except FileNotFoundError:
# if there are no, unmap the current app's windows
filebrowserwins = get_matches(get_pid(app))
if filebrowserwins:
open(wfile, "wt").write(("\n").join((" ").join(l) for l in filebrowserwins))
for w in [w[0] for w in filebrowserwins]:
subprocess.Popen(["xdotool", "windowunmap", w])
else:
arg = "--new-window" if app == "nautilus" else ""
subprocess.Popen([app, arg])
else:
# re- map unmapped windows
for w in wininf:
wid = w[0]; geo = w[3:7]
subprocess.call(["xdotool", "windowmap", wid])
subprocess.Popen(["wmctrl", "-ir", wid, "-e", "0,"+(",").join(geo)])
os.remove(wfile)
Run Code Online (Sandbox Code Playgroud)该脚本需要wmctrl和xdotool:
sudo apt-get install wmctrl xdotool
Run Code Online (Sandbox Code Playgroud)将nautilus启动器从复制/usr/share/applications到~/.local/share/applications
对于 15.04 及更高版本:
cp /usr/share/applications/org.gnome.Nautilus.desktop ~/.local/share/applications
Run Code Online (Sandbox Code Playgroud)
对于早期的 Ubuntu 版本:
cp /usr/share/applications/nautilus.desktop ~/.local/share/applications
Run Code Online (Sandbox Code Playgroud)使用 gedit 打开本地副本:
gedit ~/.local/share/applications/org.gnome.Nautilus.desktop
Run Code Online (Sandbox Code Playgroud)
(在 的情况下15.04 +)
并查找第一行,以Exec=. 改成:
Exec=python3 /path/to/remember.py
Run Code Online (Sandbox Code Playgroud)
保存并关闭文件。
使用相同的命令创建键盘快捷键:选择:系统设置 >“键盘”>“快捷键”>“自定义快捷键”。单击“+”并添加命令:
python3 /path/to/remember.py
Run Code Online (Sandbox Code Playgroud)现在注销并重新登录
使用非常简单:
要打开一个窗口,请照常执行:单击 nautilus 启动器。根据需要选择窗口:
要关闭窗口明确通过点击窗口的“关闭”(靠近它X)框。
要保留窗口及其所有选项卡:
按快捷键。窗口将消失(似乎关闭)。
下次单击启动器时,nautilus 窗口将与上次完全相同,甚至会保留窗口位置。
就是这样
Nemo 用户同样可以使用上述解决方案,但是:
在脚本的 head 部分,更改:
app = "nautilus"
Run Code Online (Sandbox Code Playgroud)
进入:
app = "nemo"
Run Code Online (Sandbox Code Playgroud)在第 3 点中,使用:
cp /usr/share/applications/nemo.desktop ~/.local/share/applications
Run Code Online (Sandbox Code Playgroud)在第 4 点中,使用:
gedit ~/.local/share/applications/nemo.desktop
Run Code Online (Sandbox Code Playgroud)经过测试,证明可以与 nemo 一起使用
| 归档时间: |
|
| 查看次数: |
3555 次 |
| 最近记录: |